Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom migration runner, forbid some diesel migration commands, fix old migrations #4673

Draft
wants to merge 86 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
ca271ea
Update schema.rs
dullbananas Apr 20, 2024
2775242
Merge branch 'LemmyNet:main' into migration-runner
dullbananas Apr 28, 2024
f2a6d73
rename
dullbananas Apr 28, 2024
691bce0
stuff
dullbananas May 4, 2024
1aab92c
Merge remote-tracking branch 'upstream/main' into migration-runner
dullbananas May 9, 2024
e8e354c
finish new implementation of schema_setup::run (not including revert,…
dullbananas May 11, 2024
402ab14
fmt
dullbananas May 11, 2024
08ae13b
refactor
dullbananas May 11, 2024
542f81d
fix sql
dullbananas May 11, 2024
d0d8139
migriation run command
dullbananas May 11, 2024
22ac8c5
use trigger on migrations table
dullbananas May 12, 2024
27b289c
add Options with disable_migrations field for test
dullbananas May 13, 2024
614e0e5
rename to enable_forbid_diesel_cli_trigger
dullbananas May 13, 2024
5d8af0d
fix
dullbananas May 17, 2024
1af517f
Merge remote-tracking branch 'upstream/main' into migration-runner
dullbananas May 17, 2024
16dcbc7
fix merge
dullbananas May 17, 2024
6709882
diff_checker (partial)
dullbananas May 17, 2024
d4bdda5
Revert "diff_checker (partial)"
dullbananas May 17, 2024
8e0bbd6
Revert "Revert "diff_checker (partial)""
dullbananas May 17, 2024
1692fd6
diff check
dullbananas May 18, 2024
84bf57e
improve schema diff
dullbananas May 18, 2024
d18c2c9
timestamp replacement
dullbananas May 18, 2024
314e744
ignore column order
dullbananas May 18, 2024
80ca94e
remove fedi_name default
dullbananas May 18, 2024
06b01ff
stuff
dullbananas May 19, 2024
7977ee1
improve diff
dullbananas May 19, 2024
ced9bb5
stuff
dullbananas May 20, 2024
592a127
attempt parallel pg_dump
dullbananas May 20, 2024
a909d2d
attempt 2
dullbananas May 20, 2024
47a4c35
Revert "attempt 2"
dullbananas May 20, 2024
9a528fb
Revert "attempt parallel pg_dump"
dullbananas May 20, 2024
5596cb7
improve diff check
dullbananas May 20, 2024
6eb8d04
finish fixing migrations
dullbananas May 20, 2024
cf5afc9
stuff
dullbananas May 21, 2024
4d427b2
use advisory lock
dullbananas May 21, 2024
5fca4ea
Merge remote-tracking branch 'upstream/main' into migration-runner
dullbananas May 21, 2024
d71cfaa
stuff
dullbananas May 22, 2024
cdbe77c
Update lib.rs
dullbananas May 22, 2024
f1142e0
Merge branch 'main' into migration-runner
dullbananas May 22, 2024
7716c9e
fmt
dullbananas May 22, 2024
c7babd7
fmt
dullbananas May 22, 2024
e5bc0bb
clippy
dullbananas May 22, 2024
f0b2f0d
Update diff_check.rs
dullbananas May 22, 2024
d2f772a
Update .woodpecker.yml
dullbananas May 22, 2024
0443bcd
Update lib.rs
dullbananas May 22, 2024
ab8c7d8
Update lib.rs
dullbananas May 22, 2024
7f550e1
Update lib.rs
dullbananas May 23, 2024
6f6a5c9
Update .woodpecker.yml
dullbananas May 23, 2024
132877c
Update .woodpecker.yml
dullbananas May 23, 2024
0969fd3
Update lib.rs
dullbananas May 23, 2024
64827a1
re-run ci
dullbananas May 23, 2024
833a250
Merge branch 'main' into migration-runner
dullbananas May 23, 2024
3f3b8e3
fmt
dullbananas May 23, 2024
0a02ceb
fmt
dullbananas May 23, 2024
de1c688
Update .woodpecker.yml
dullbananas May 23, 2024
0f37356
Update .woodpecker.yml
dullbananas May 23, 2024
728b6d4
create separate database in ci
dullbananas May 23, 2024
f252de1
Update .woodpecker.yml
dullbananas May 23, 2024
f9af3de
Update .woodpecker.yml
dullbananas May 23, 2024
1e56bde
Update .woodpecker.yml
dullbananas May 23, 2024
1a71897
Update .woodpecker.yml
dullbananas May 23, 2024
d57d293
try to fix env var
dullbananas May 23, 2024
56e22b0
Update diff_check.rs
dullbananas May 23, 2024
db856ef
Merge branch 'main' into migration-runner
dullbananas May 23, 2024
d82bfcc
Remove condition that's not needed anymore
dullbananas May 26, 2024
c694da9
clippy
dullbananas May 27, 2024
120be51
exclude views and fast tables
dullbananas May 27, 2024
317097c
revert some migration changes
dullbananas May 27, 2024
b6102dc
fix
dullbananas May 27, 2024
1a18350
fmt
dullbananas May 27, 2024
d592e0f
re-attempt checking character after skipped trigger name, and make co…
dullbananas May 28, 2024
3daa0d6
fmt
dullbananas May 28, 2024
0b8790c
Merge branch 'main' into migration-runner
dullbananas May 28, 2024
ce1cf3e
fix
dullbananas May 28, 2024
45562bf
rerun ci
dullbananas May 28, 2024
b176340
rerun ci
dullbananas May 28, 2024
a242333
fix strip_prefix order
dullbananas May 28, 2024
7734ba4
Merge remote-tracking branch 'upstream/main' into migration-runner
dullbananas Jun 25, 2024
de01635
Merge remote-tracking branch 'upstream/main' into migration-runner
dullbananas Jul 3, 2024
de0e025
fix weird big Cargo.lock change by running `git checkout upstream/mai…
dullbananas Jul 3, 2024
4428c61
Merge remote-tracking branch 'upstream/main' into migration-runner
dullbananas Jul 26, 2024
84b161d
fix
dullbananas Jul 26, 2024
ecb700e
Merge remote-tracking branch 'upstream/main' into migration-runner
dullbananas Aug 21, 2024
fd65234
remove installation commands that were removed in main branch
dullbananas Aug 21, 2024
6345b2d
Revert "remove installation commands that were removed in main branch"
dullbananas Aug 23, 2024
f636f1a
Merge upstream/main into migration-runner (using imerge)
dullbananas Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 31 additions & 42 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ steps:
- diff config/defaults.hjson config/defaults_current.hjson
when: *slow_check_paths

check_diesel_schema:
image: *rust_image
# `DROP OWNED` doesn't work for default user
create_database_user:
image: postgres:16-alpine
environment:
CARGO_HOME: .cargo_home
DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
PGUSER: postgres
PGPASSWORD: password
PGHOST: database
PGDATABASE: lemmy
commands:
- <<: *install_diesel_cli
- cp crates/db_schema/src/schema.rs tmp.schema
- diesel migration run
- diff tmp.schema crates/db_schema/src/schema.rs
- psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;"
when: *slow_check_paths

check_db_perf_tool:
Expand Down Expand Up @@ -167,6 +167,21 @@ steps:
- mv target/debug/lemmy_server target/lemmy_server
when: *slow_check_paths

check_diesel_schema:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
commands:
- cp crates/db_schema/src/schema.rs tmp.schema
- target/lemmy_server migration --all run
- <<: *install_diesel_cli
- diesel print-schema
- diff tmp.schema crates/db_schema/src/schema.rs
when: *slow_check_paths

cargo_test:
image: *rust_image
environment:
Expand All @@ -176,6 +191,12 @@ steps:
LEMMY_TEST_FAST_FEDERATION: "1"
LEMMY_CONFIG_LOCATION: ../../config/config.hjson
commands:
# Install pg_dump for the schema setup test (must match server version)
- apt update && apt install -y lsb-release
- sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
- apt update && apt install -y postgresql-client-16
# Run tests
- cargo test --workspace --no-fail-fast
when: *slow_check_paths

Expand All @@ -188,39 +209,6 @@ steps:
when:
- event: pull_request

check_diesel_migration:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't check / test the migrations anymore in CI?

# TODO: use willsquire/diesel-cli image when shared libraries become optional in lemmy_server
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
PGUSER: lemmy
PGPASSWORD: password
PGHOST: database
PGDATABASE: lemmy
commands:
# Install diesel_cli
- <<: *install_diesel_cli
# Run all migrations
- diesel migration run
- psql -c "DROP SCHEMA IF EXISTS r CASCADE;"
- pg_dump --no-owner --no-privileges --no-table-access-method --schema-only --no-sync -f before.sqldump
# Make sure that the newest migration is revertable without the `r` schema
- diesel migration redo
# Run schema setup twice, which fails on the 2nd time if `DROP SCHEMA IF EXISTS r CASCADE` drops the wrong things
- alias lemmy_schema_setup="target/lemmy_server --disable-scheduled-tasks --disable-http-server --disable-activity-sending"
- lemmy_schema_setup
- lemmy_schema_setup
# Make sure that the newest migration is revertable with the `r` schema
- diesel migration redo
# Check for changes in the schema, which would be caused by an incorrect migration
- psql -c "DROP SCHEMA IF EXISTS r CASCADE;"
- pg_dump --no-owner --no-privileges --no-table-access-method --schema-only --no-sync -f after.sqldump
- diff before.sqldump after.sqldump
when: *slow_check_paths

run_federation_tests:
image: node:22-bookworm-slim
environment:
Expand Down Expand Up @@ -312,5 +300,6 @@ services:
# 15-alpine image necessary because of diesel tests
image: pgautoupgrade/pgautoupgrade:15-alpine
environment:
POSTGRES_USER: lemmy
POSTGRES_DB: lemmy
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/db_schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ tuplex = { workspace = true, optional = true }
[dev-dependencies]
serial_test = { workspace = true }
pretty_assertions = { workspace = true }
diff = "0.1.13"
7 changes: 1 addition & 6 deletions crates/db_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ extern crate diesel_derive_newtype;
#[macro_use]
extern crate diesel_derive_enum;

// this is used in tests
#[cfg(feature = "full")]
#[macro_use]
extern crate diesel_migrations;

#[cfg(feature = "full")]
#[macro_use]
extern crate async_trait;
Expand Down Expand Up @@ -44,7 +39,7 @@ pub mod traits;
pub mod utils;

#[cfg(feature = "full")]
mod schema_setup;
pub mod schema_setup;

use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};
Expand Down
8 changes: 8 additions & 0 deletions crates/db_schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,13 @@ diesel::table! {
}
}

diesel::table! {
previously_run_sql (id) {
id -> Bool,
content -> Text,
}
}

diesel::table! {
private_message (id) {
id -> Int4,
Expand Down Expand Up @@ -1062,6 +1069,7 @@ diesel::allow_tables_to_appear_in_same_query!(
post_actions,
post_aggregates,
post_report,
previously_run_sql,
private_message,
private_message_report,
received_activity,
Expand Down
Loading