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 13remove_ansible_tagging
parent
f5511cfd25
commit
d8722b6e91
@ -0,0 +1,36 @@ |
||||
diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs
|
||||
index 255c6422..f2ccf5e2 100644
|
||||
--- a/crates/db_schema/src/schema.rs
|
||||
+++ b/crates/db_schema/src/schema.rs
|
||||
@@ -2,16 +2,12 @@
|
||||
|
||||
pub mod sql_types {
|
||||
#[derive(diesel::sql_types::SqlType)]
|
||||
#[diesel(postgres_type(name = "listing_type_enum"))]
|
||||
pub struct ListingTypeEnum;
|
||||
|
||||
- #[derive(diesel::sql_types::SqlType)]
|
||||
- #[diesel(postgres_type(name = "ltree"))]
|
||||
- pub struct Ltree;
|
||||
-
|
||||
#[derive(diesel::sql_types::SqlType)]
|
||||
#[diesel(postgres_type(name = "registration_mode_enum"))]
|
||||
pub struct RegistrationModeEnum;
|
||||
|
||||
#[derive(diesel::sql_types::SqlType)]
|
||||
#[diesel(postgres_type(name = "sort_type_enum"))]
|
||||
@@ -67,13 +63,13 @@ diesel::table! {
|
||||
when_ -> Timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
use diesel::sql_types::*;
|
||||
- use super::sql_types::Ltree;
|
||||
+ use diesel_ltree::sql_types::Ltree;
|
||||
|
||||
comment (id) {
|
||||
id -> Int4,
|
||||
creator_id -> Int4,
|
||||
post_id -> Int4,
|
||||
content -> Text,
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@ |
||||
[print_schema] |
||||
file = "crates/db_schema/src/schema.rs" |
||||
patch_file = "crates/db_schema/src/diesel_ltree.patch" |
@ -0,0 +1,62 @@ |
||||
-- 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; |
@ -0,0 +1,61 @@ |
||||
-- A few DB fixes |
||||
alter table community alter column hidden set not null; |
||||
alter table community alter column posting_restricted_to_mods set not null; |
||||
alter table activity alter column sensitive set not null; |
||||
alter table mod_add alter column removed set not null; |
||||
alter table mod_add_community alter column removed set not null; |
||||
alter table mod_ban alter column banned set not null; |
||||
alter table mod_ban_from_community alter column banned set not null; |
||||
alter table mod_hide_community alter column hidden set not null; |
||||
alter table mod_lock_post alter column locked set not null; |
||||
alter table mod_remove_comment alter column removed set not null; |
||||
alter table mod_remove_community alter column removed set not null; |
||||
alter table mod_remove_post alter column removed set not null; |
||||
alter table mod_transfer_community drop column removed; |
||||
alter table language alter column code set not null; |
||||
alter table language alter column name set not null; |
||||
|
||||
-- Fix the registration mode enums |
||||
ALTER TYPE registration_mode_enum RENAME VALUE 'closed' TO 'Closed'; |
||||
ALTER TYPE registration_mode_enum RENAME VALUE 'require_application' TO 'RequireApplication'; |
||||
ALTER TYPE registration_mode_enum RENAME VALUE 'open' TO 'Open'; |
||||
|
||||
-- Create the enums |
||||
|
||||
CREATE TYPE sort_type_enum AS ENUM ('Active', 'Hot', 'New', 'Old', 'TopDay', 'TopWeek', 'TopMonth', 'TopYear', 'TopAll', 'MostComments', 'NewComments'); |
||||
|
||||
CREATE TYPE listing_type_enum AS ENUM ('All', 'Local', 'Subscribed'); |
||||
|
||||
-- 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 sort_type_enum using |
||||
case default_sort_type |
||||
when 0 then 'Active' |
||||
when 1 then 'Hot' |
||||
when 2 then 'New' |
||||
when 3 then 'Old' |
||||
when 4 then 'TopDay' |
||||
when 5 then 'TopWeek' |
||||
when 6 then 'TopMonth' |
||||
when 7 then 'TopYear' |
||||
when 8 then 'TopAll' |
||||
when 9 then 'MostComments' |
||||
when 10 then 'NewComments' |
||||
else 'Active' |
||||
end :: sort_type_enum; |
||||
alter table local_user alter column default_sort_type set default 'Active'; |
||||
|
||||
alter table local_user alter column default_listing_type drop default; |
||||
alter table local_user alter column default_listing_type type listing_type_enum using |
||||
case default_listing_type |
||||
when 0 then 'All' |
||||
when 1 then 'Local' |
||||
when 2 then 'Subscribed' |
||||
else 'Local' |
||||
end :: listing_type_enum; |
||||
alter table local_user alter column default_listing_type set default 'Local'; |
||||
|
||||
-- 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 listing_type_enum using default_post_listing_type::listing_type_enum; |
||||
alter table local_site alter column default_post_listing_type set default 'Local'; |
Loading…
Reference in new issue