mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-28 13:51:32 +00:00
stuff
This commit is contained in:
parent
7977ee166a
commit
ced9bb5216
13 changed files with 130 additions and 20 deletions
|
@ -21,7 +21,6 @@ pub fn get_dump(conn: &mut PgConnection) -> String {
|
||||||
.get_result::<String>(conn)
|
.get_result::<String>(conn)
|
||||||
.expect("pg_export_snapshot failed");
|
.expect("pg_export_snapshot failed");
|
||||||
let snapshot_arg = format!("--snapshot={snapshot}");*/
|
let snapshot_arg = format!("--snapshot={snapshot}");*/
|
||||||
|
|
||||||
let output = Command::new("pg_dump")
|
let output = Command::new("pg_dump")
|
||||||
.args(["--schema-only"])
|
.args(["--schema-only"])
|
||||||
.env("DATABASE_URL", SETTINGS.get_database_url())
|
.env("DATABASE_URL", SETTINGS.get_database_url())
|
||||||
|
@ -40,6 +39,9 @@ const PATTERN_LEN: usize = 19;
|
||||||
// TODO add unit test for output
|
// TODO add unit test for output
|
||||||
pub fn check_dump_diff(conn: &mut PgConnection, mut before: String, name: &str) {
|
pub fn check_dump_diff(conn: &mut PgConnection, mut before: String, name: &str) {
|
||||||
let mut after = get_dump(conn);
|
let mut after = get_dump(conn);
|
||||||
|
if after == before {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Ignore timestamp differences by removing timestamps
|
// Ignore timestamp differences by removing timestamps
|
||||||
for dump in [&mut before, &mut after] {
|
for dump in [&mut before, &mut after] {
|
||||||
for index in 0.. {
|
for index in 0.. {
|
||||||
|
@ -74,9 +76,6 @@ pub fn check_dump_diff(conn: &mut PgConnection, mut before: String, name: &str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if after == before {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let [before_chunks, after_chunks] =
|
let [before_chunks, after_chunks] =
|
||||||
[&before, &after].map(|dump| chunks(dump).collect::<BTreeSet<_>>());
|
[&before, &after].map(|dump| chunks(dump).collect::<BTreeSet<_>>());
|
||||||
|
|
||||||
|
@ -102,8 +101,8 @@ pub fn check_dump_diff(conn: &mut PgConnection, mut before: String, name: &str)
|
||||||
}
|
}
|
||||||
let after_has_more =
|
let after_has_more =
|
||||||
only_in_before.len() < only_in_after.len();
|
only_in_before.len() < only_in_after.len();
|
||||||
// outer iterator in the loop below should be the one with empty strings, otherwise the empty strings
|
// outer iterator in the loop below should not be the one with empty strings, otherwise the empty strings
|
||||||
// would appear to have the most similarity
|
// would be equally similar to any other chunk
|
||||||
let (chunks_gt, chunks_lt) = if after_has_more
|
let (chunks_gt, chunks_lt) = if after_has_more
|
||||||
{
|
{
|
||||||
only_in_before.resize_with(only_in_after.len(),Default::default);
|
only_in_before.resize_with(only_in_after.len(),Default::default);
|
||||||
|
@ -118,15 +117,15 @@ pub fn check_dump_diff(conn: &mut PgConnection, mut before: String, name: &str)
|
||||||
for (before_chunk, before_chunk_filtered) in chunks_lt {
|
for (before_chunk, before_chunk_filtered) in chunks_lt {
|
||||||
let default = Default::default();
|
let default = Default::default();
|
||||||
//panic!("{:?}",(before_chunk.clone(),chunks_lt.clone()));
|
//panic!("{:?}",(before_chunk.clone(),chunks_lt.clone()));
|
||||||
let (most_similar_chunk_index, (most_similar_chunk, _)) = chunks_gt
|
let (most_similar_chunk_index, (most_similar_chunk, most_similar_chunk_filtered)) = chunks_gt
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.max_by_key(|(_, (after_chunk, after_chunk_filtered))| {
|
.max_by_key(|(_, (after_chunk, after_chunk_filtered))| {
|
||||||
diff::chars(after_chunk_filtered, &before_chunk_filtered)
|
diff::chars(after_chunk_filtered, &before_chunk_filtered)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|i| matches!(i, diff::Result::Both(c, _)
|
.filter(|i| matches!(i, diff::Result::Both(c, _)
|
||||||
// This increases accuracy for some trigger function diffs
|
// `is_lowercase` increases accuracy for some trigger function diffs
|
||||||
if c.is_lowercase()))
|
if c.is_lowercase() || c.is_numeric()))
|
||||||
.count()
|
.count()
|
||||||
})
|
})
|
||||||
.unwrap_or((0,&default));
|
.unwrap_or((0,&default));
|
||||||
|
@ -143,6 +142,7 @@ pub fn check_dump_diff(conn: &mut PgConnection, mut before: String, name: &str)
|
||||||
}
|
}
|
||||||
.expect("failed to build string");
|
.expect("failed to build string");
|
||||||
}
|
}
|
||||||
|
write!(&mut output, "\n{most_similar_chunk_filtered}");
|
||||||
if !chunks_gt.is_empty() {
|
if !chunks_gt.is_empty() {
|
||||||
chunks_gt.swap_remove(most_similar_chunk_index);}
|
chunks_gt.swap_remove(most_similar_chunk_index);}
|
||||||
}
|
}
|
||||||
|
@ -178,6 +178,37 @@ fn chunks<'a>(dump: &'a str) -> impl Iterator<Item = Cow<'a, str>> {
|
||||||
(placement, line)
|
(placement, line)
|
||||||
});
|
});
|
||||||
Cow::Owned(lines.join("\n"))
|
Cow::Owned(lines.join("\n"))
|
||||||
|
} else if result.starts_with("CREATE VIEW") || result.starts_with("CREATE OR REPLACE VIEW") {
|
||||||
|
// Allow column order to change
|
||||||
|
let is_simple_select_statement = result
|
||||||
|
.lines()
|
||||||
|
.enumerate()
|
||||||
|
.all(|(i, mut line)| {
|
||||||
|
line = line.trim_start();
|
||||||
|
match (i, line.chars().next()) {
|
||||||
|
(0, Some('C')) => true, // create
|
||||||
|
(1, Some('S')) => true, // select
|
||||||
|
(_, Some('F')) if line.ends_with(';') => true, // from
|
||||||
|
(_, Some(c)) if c.is_lowercase() => true, // column name
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if is_simple_select_statement {
|
||||||
|
let mut lines = result
|
||||||
|
.lines()
|
||||||
|
.map(|line| line.strip_suffix(',').unwrap_or(line))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
lines.sort_unstable_by_key(|line| -> (u8, &str) {
|
||||||
|
let placement = match line.trim_start().chars().next() {
|
||||||
|
Some('C') => 0,
|
||||||
|
Some('S') => 1,
|
||||||
|
Some('F') => 3,
|
||||||
|
_ => 2,
|
||||||
|
};
|
||||||
|
(placement, line)
|
||||||
|
});
|
||||||
|
Cow::Owned(lines.join("\n"))
|
||||||
|
}else{Cow::Borrowed(result)}
|
||||||
} else {
|
} else {
|
||||||
Cow::Borrowed(result)
|
Cow::Borrowed(result)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
ALTER TABLE activity
|
ALTER TABLE activity
|
||||||
ADD COLUMN user_id INTEGER;
|
ADD COLUMN user_id INTEGER NOT NULL REFERENCES user_(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||||
|
|
||||||
ALTER TABLE activity
|
ALTER TABLE activity
|
||||||
DROP COLUMN sensitive;
|
DROP COLUMN sensitive;
|
||||||
|
|
|
@ -34,5 +34,9 @@ INSERT INTO category (name)
|
||||||
ALTER TABLE community
|
ALTER TABLE community
|
||||||
ADD category_id int REFERENCES category ON UPDATE CASCADE ON DELETE CASCADE NOT NULL DEFAULT 1;
|
ADD category_id int REFERENCES category ON UPDATE CASCADE ON DELETE CASCADE NOT NULL DEFAULT 1;
|
||||||
|
|
||||||
|
-- Default is only for existing rows
|
||||||
|
ALTER TABLE community
|
||||||
|
ALTER COLUMN category_id DROP DEFAULT;
|
||||||
|
|
||||||
CREATE INDEX idx_community_category ON community (category_id);
|
CREATE INDEX idx_community_category ON community (category_id);
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,7 @@ ALTER SEQUENCE person_id_seq
|
||||||
-- Add the columns back in
|
-- Add the columns back in
|
||||||
ALTER TABLE user_
|
ALTER TABLE user_
|
||||||
ADD COLUMN password_encrypted text NOT NULL DEFAULT 'changeme',
|
ADD COLUMN password_encrypted text NOT NULL DEFAULT 'changeme',
|
||||||
ADD COLUMN email text,
|
ADD COLUMN email text UNIQUE,
|
||||||
ADD COLUMN admin boolean DEFAULT FALSE NOT NULL,
|
ADD COLUMN admin boolean DEFAULT FALSE NOT NULL,
|
||||||
ADD COLUMN show_nsfw boolean DEFAULT FALSE NOT NULL,
|
ADD COLUMN show_nsfw boolean DEFAULT FALSE NOT NULL,
|
||||||
ADD COLUMN theme character varying(20) DEFAULT 'darkly'::character varying NOT NULL,
|
ADD COLUMN theme character varying(20) DEFAULT 'darkly'::character varying NOT NULL,
|
||||||
|
@ -238,7 +238,10 @@ ALTER TABLE user_
|
||||||
ADD COLUMN lang character varying(20) DEFAULT 'browser'::character varying NOT NULL,
|
ADD COLUMN lang character varying(20) DEFAULT 'browser'::character varying NOT NULL,
|
||||||
ADD COLUMN show_avatars boolean DEFAULT TRUE NOT NULL,
|
ADD COLUMN show_avatars boolean DEFAULT TRUE NOT NULL,
|
||||||
ADD COLUMN send_notifications_to_email boolean DEFAULT FALSE NOT NULL,
|
ADD COLUMN send_notifications_to_email boolean DEFAULT FALSE NOT NULL,
|
||||||
ADD COLUMN matrix_user_id text;
|
ADD COLUMN matrix_user_id text UNIQUE;
|
||||||
|
|
||||||
|
-- Default is only for existing rows
|
||||||
|
alter table user_ alter column password_encrypted drop default;
|
||||||
|
|
||||||
-- Update the user_ table with the local_user data
|
-- Update the user_ table with the local_user data
|
||||||
UPDATE
|
UPDATE
|
||||||
|
@ -264,13 +267,63 @@ CREATE UNIQUE INDEX idx_user_email_lower ON user_ (lower(email));
|
||||||
|
|
||||||
CREATE VIEW user_alias_1 AS
|
CREATE VIEW user_alias_1 AS
|
||||||
SELECT
|
SELECT
|
||||||
*
|
id,
|
||||||
|
actor_id,
|
||||||
|
admin,
|
||||||
|
avatar,
|
||||||
|
banned,
|
||||||
|
banner,
|
||||||
|
bio,
|
||||||
|
default_listing_type,
|
||||||
|
default_sort_type,
|
||||||
|
deleted,
|
||||||
|
email,
|
||||||
|
lang,
|
||||||
|
last_refreshed_at,
|
||||||
|
local,
|
||||||
|
matrix_user_id,
|
||||||
|
name,
|
||||||
|
password_encrypted,
|
||||||
|
preferred_username,
|
||||||
|
private_key,
|
||||||
|
public_key,
|
||||||
|
published,
|
||||||
|
send_notifications_to_email,
|
||||||
|
show_avatars,
|
||||||
|
show_nsfw,
|
||||||
|
theme,
|
||||||
|
updated
|
||||||
FROM
|
FROM
|
||||||
user_;
|
user_;
|
||||||
|
|
||||||
CREATE VIEW user_alias_2 AS
|
CREATE VIEW user_alias_2 AS
|
||||||
SELECT
|
SELECT
|
||||||
*
|
id,
|
||||||
|
actor_id,
|
||||||
|
admin,
|
||||||
|
avatar,
|
||||||
|
banned,
|
||||||
|
banner,
|
||||||
|
bio,
|
||||||
|
default_listing_type,
|
||||||
|
default_sort_type,
|
||||||
|
deleted,
|
||||||
|
email,
|
||||||
|
lang,
|
||||||
|
last_refreshed_at,
|
||||||
|
local,
|
||||||
|
matrix_user_id,
|
||||||
|
name,
|
||||||
|
password_encrypted,
|
||||||
|
preferred_username,
|
||||||
|
private_key,
|
||||||
|
public_key,
|
||||||
|
published,
|
||||||
|
send_notifications_to_email,
|
||||||
|
show_avatars,
|
||||||
|
show_nsfw,
|
||||||
|
theme,
|
||||||
|
updated
|
||||||
FROM
|
FROM
|
||||||
user_;
|
user_;
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
DROP TABLE secret;
|
DROP TABLE secret;
|
||||||
|
|
||||||
|
DROP EXTENSION pgcrypto;
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,7 @@ CREATE INDEX idx_path_gist ON comment USING gist (path);
|
||||||
|
|
||||||
-- Drop the parent_id column
|
-- Drop the parent_id column
|
||||||
ALTER TABLE comment
|
ALTER TABLE comment
|
||||||
DROP COLUMN parent_id CASCADE,add column if not exists poop int;alter table post add column if not exists poop int;
|
DROP COLUMN parent_id CASCADE;
|
||||||
|
|
||||||
ALTER TABLE comment ENABLE TRIGGER USER;
|
ALTER TABLE comment ENABLE TRIGGER USER;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ ALTER TABLE site
|
||||||
ADD COLUMN community_creation_admin_only boolean DEFAULT FALSE NOT NULL,
|
ADD COLUMN community_creation_admin_only boolean DEFAULT FALSE NOT NULL,
|
||||||
ADD COLUMN require_email_verification boolean DEFAULT FALSE NOT NULL,
|
ADD COLUMN require_email_verification boolean DEFAULT FALSE NOT NULL,
|
||||||
ADD COLUMN require_application boolean DEFAULT TRUE NOT NULL,
|
ADD COLUMN require_application boolean DEFAULT TRUE NOT NULL,
|
||||||
ADD COLUMN application_question text DEFAULT 'to verify that you are human, please explain why you want to create an account on this site'::text,
|
ADD COLUMN application_question text DEFAULT 'To verify that you are human, please explain why you want to create an account on this site'::text,
|
||||||
ADD COLUMN private_instance boolean DEFAULT FALSE NOT NULL,
|
ADD COLUMN private_instance boolean DEFAULT FALSE NOT NULL,
|
||||||
ADD COLUMN default_theme text DEFAULT 'browser'::text NOT NULL,
|
ADD COLUMN default_theme text DEFAULT 'browser'::text NOT NULL,
|
||||||
ADD COLUMN default_post_listing_type text DEFAULT 'Local'::text NOT NULL,
|
ADD COLUMN default_post_listing_type text DEFAULT 'Local'::text NOT NULL,
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
ALTER TABLE local_site
|
ALTER TABLE local_site
|
||||||
ADD COLUMN federation_debug int DEFAULT 0;
|
ADD COLUMN federation_debug boolean DEFAULT false not null;
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ ALTER TABLE local_site
|
||||||
ALTER COLUMN default_post_listing_type TYPE text;
|
ALTER COLUMN default_post_listing_type TYPE text;
|
||||||
|
|
||||||
ALTER TABLE local_site
|
ALTER TABLE local_site
|
||||||
ALTER COLUMN default_post_listing_type SET DEFAULT 1;
|
ALTER COLUMN default_post_listing_type SET DEFAULT 'Local';
|
||||||
|
|
||||||
-- Drop the types
|
-- Drop the types
|
||||||
DROP TYPE listing_type_enum;
|
DROP TYPE listing_type_enum;
|
||||||
|
|
|
@ -6,3 +6,5 @@ DROP INDEX idx_person_trigram;
|
||||||
|
|
||||||
DROP INDEX idx_community_trigram;
|
DROP INDEX idx_community_trigram;
|
||||||
|
|
||||||
|
DROP EXTENSION pg_trgm;
|
||||||
|
|
||||||
|
|
|
@ -85,3 +85,21 @@ ALTER TABLE local_user
|
||||||
-- drop the old enum
|
-- drop the old enum
|
||||||
DROP TYPE sort_type_enum__;
|
DROP TYPE sort_type_enum__;
|
||||||
|
|
||||||
|
-- Remove int to float conversions that were automatically added to index filters
|
||||||
|
DROP INDEX
|
||||||
|
idx_comment_aggregates_nonzero_hotrank,
|
||||||
|
idx_community_aggregates_nonzero_hotrank,
|
||||||
|
idx_post_aggregates_nonzero_hotrank;
|
||||||
|
|
||||||
|
CREATE INDEX idx_community_aggregates_nonzero_hotrank ON community_aggregates (published)
|
||||||
|
WHERE
|
||||||
|
hot_rank != 0;
|
||||||
|
|
||||||
|
CREATE INDEX idx_comment_aggregates_nonzero_hotrank ON comment_aggregates (published)
|
||||||
|
WHERE
|
||||||
|
hot_rank != 0;
|
||||||
|
|
||||||
|
CREATE INDEX idx_post_aggregates_nonzero_hotrank ON post_aggregates (published DESC)
|
||||||
|
WHERE
|
||||||
|
hot_rank != 0 OR hot_rank_active != 0;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
DROP TABLE login_token;
|
DROP TABLE login_token;
|
||||||
|
|
||||||
ALTER TABLE local_user
|
ALTER TABLE local_user
|
||||||
ADD COLUMN validator_time timestamp NOT NULL DEFAULT now();
|
ADD COLUMN validator_time timestamptz NOT NULL DEFAULT now();
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
ALTER TABLE mod_remove_community
|
ALTER TABLE mod_remove_community
|
||||||
ADD COLUMN expires timestamp;
|
ADD COLUMN expires timestamptz;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue