lemmy/migrations/2023-04-14-175955_add_listingtype_sorttype_enums/down.sql
Dessalines d8722b6e91
Adding diesel enums for SortType and ListingType (#2808)
* Adding diesel enums for SortType and ListingType

- Uses diesel-derive-enum.
- Adds diesel.toml , so we can again use the auto-generated schema.rs
- Fixes a lot of DB null issues and column ordering issues.
- Fixes #1136
- Also replaces RegistrationMode boilerplate.

* Fixing unit tests 1.

* Remove comment line.

* Before patch.

* Before again.

* Using patch file to fix diesel_ltree issue with diesel.toml

* Adding some yalc ignores

* Fixing RegistrationMode enums

* Adding woodpecker diesel schema check.

* Try adding openssl 1.

* Try using diesel-cli image 1

* Try using diesel-cli image 2

* Try using diesel-cli image 3

* Try using diesel-cli image 4

* Try using diesel-cli image 5

* Try using diesel-cli image 6

* Try using diesel-cli image 7

* Try using diesel-cli image 8

* Try using diesel-cli image 9

* Try using diesel-cli image 10

* Try using diesel-cli image 11

* Try using diesel-cli image 12

* Try using diesel-cli image 13
2023-04-17 15:19:51 -04:00

63 lines
2.5 KiB
SQL

-- Some fixes
alter table community alter column hidden drop not null;
alter table community alter column posting_restricted_to_mods drop not null;
alter table activity alter column sensitive drop not null;
alter table mod_add alter column removed drop not null;
alter table mod_add_community alter column removed drop not null;
alter table mod_ban alter column banned drop not null;
alter table mod_ban_from_community alter column banned drop not null;
alter table mod_hide_community alter column hidden drop not null;
alter table mod_lock_post alter column locked drop not null;
alter table mod_remove_comment alter column removed drop not null;
alter table mod_remove_community alter column removed drop not null;
alter table mod_remove_post alter column removed drop not null;
alter table mod_transfer_community add column removed boolean default false;
alter table language alter column code drop not null;
alter table language alter column name drop not null;
-- Fix the registration mode enums
ALTER TYPE registration_mode_enum RENAME VALUE 'Closed' TO 'closed';
ALTER TYPE registration_mode_enum RENAME VALUE 'RequireApplication' TO 'require_application';
ALTER TYPE registration_mode_enum RENAME VALUE 'Open' TO 'open';
-- add back old columns
-- Alter the local_user table
alter table local_user alter column default_sort_type drop default;
alter table local_user alter column default_sort_type type smallint using
case default_sort_type
when 'Active' then 0
when 'Hot' then 1
when 'New' then 2
when 'Old' then 3
when 'TopDay' then 4
when 'TopWeek' then 5
when 'TopMonth' then 6
when 'TopYear' then 7
when 'TopAll' then 8
when 'MostComments' then 9
when 'NewComments' then 10
else 0
end;
alter table local_user alter column default_sort_type set default 0;
alter table local_user alter column default_listing_type drop default;
alter table local_user alter column default_listing_type type smallint using
case default_listing_type
when 'All' then 0
when 'Local' then 1
when 'Subscribed' then 2
else 1
end;
alter table local_user alter column default_listing_type set default 1;
-- Alter the local site column
alter table local_site alter column default_post_listing_type drop default;
alter table local_site alter column default_post_listing_type type text;
alter table local_site alter column default_post_listing_type set default 1;
-- Drop the types
drop type listing_type_enum;
drop type sort_type_enum;