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

Make DB migrations idempotent. #1678

Merged
merged 1 commit into from
Oct 3, 2021
Merged

Make DB migrations idempotent. #1678

merged 1 commit into from
Oct 3, 2021

Conversation

Rjevski
Copy link
Contributor

@Rjevski Rjevski commented Jan 17, 2021

Fixes #1772

This is more of a discussion than anything else - the provided code will work and maybe should be merged, but I don't think it's a complete solution.

Currently we don't seem to have a good system for database migrations. The scripts in config/migrate-scripts seem to be written manually, hardcode a database name and username, expect to be ran on the local machine and don't use the SQL files in config/sql (so it's one extra thing that needs to be manually kept in sync). They're also not aware of the current database state, so an automated deployment pipeline can't tell whether it needs to run them (or if they were already applied) and the SQL in there doesn't seem to be idempotent which means it will fail because those tables are already there.

I don't think implementing our own migration system is the way to go. If Crystal has something "standard" for it I suggest we use that, otherwise we could consider Alembic?

The reason behind this is that I'm trying (well, I've succeeded - with workarounds and hacks) to deploy Invidious on a PaaS such as Dokku. The PaaS deploy process allows you to run a "post-release" command which is where database migrations should go. Most web frameworks automatically detect which migrations are applied so it's safe to run the command on every deploy even if no migrations are pending; unfortunately Invidious does not have this. This change makes the migrations idempotent (by using IF NOT EXISTS on the create statements) so any subsequent runs will not error out.

(
id text NOT NULL,
annotations xml,
CONSTRAINT annotations_id_key UNIQUE (id)
);

GRANT ALL ON TABLE public.annotations TO kemal;
GRANT ALL ON TABLE public.annotations TO current_user;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using current_user so we no longer hardcode the username to kemal and will take whatever's provided by the config or environment variable.

@TheFrenchGhosty TheFrenchGhosty added the need-code-review A crystal developper need to check if the code is correct. label Jan 18, 2021
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/nonces.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/annotations.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlists.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlist_videos.sql
Copy link
Member

Choose a reason for hiding this comment

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

What's the benefit of removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This prevents the command from stopping if errors are encountered while processing the set of SQL statements. Some statements do not have a IF NOT EXISTS clause which means we'd try to create the object all the time and thus error - in that case I'd prefer if the script continued as-is and hope for the best.

@saltycrys
Copy link
Member

This is off-topic but there are also some migrations in the code:

@Perflyst
Copy link
Contributor

Perflyst commented Jan 19, 2021

The PaaS deploy process allows you to run a "post-release" command which is where database migrations should go.

Invidious has an option called check_tables which, I think, can do migrations automatically.

@TheFrenchGhosty TheFrenchGhosty added unfinished More work is needed on this PR, or on something this PR uses. and removed need-code-review A crystal developper need to check if the code is correct. labels Jan 21, 2021
@Rjevski
Copy link
Contributor Author

Rjevski commented Feb 13, 2021

@Perflyst looking at the code, it seems like check_tables will internally use the SQL files in config to do its migrations, so the change to assign to current_user instead of hardcoded kemal is still necessary if running Invidious with a DB user other than kemal (like on PaaS where the DB credentials are provided by the platform with no way to change them).

It seems like the shell scripts for migrating can be deleted though as check_tables does the equivalent.

@github-actions
Copy link

This pull request has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely abandoned or outdated. If you think this pull request is still relevant and applicable, you just have to post a comment and it will be unmarked.

@github-actions github-actions bot added the stale label Jun 19, 2021
@SamantazFox
Copy link
Member

bump, still relevant!

@Rjevski
Copy link
Contributor Author

Rjevski commented Jun 19, 2021

I'm going to unsubscribe from notifications as I predict this close-unclose cycle every 30 days is going to go for a while so please email me or tag me in a new issue if there is any more work or input required on this!

@SamantazFox
Copy link
Member

SamantazFox commented Jun 19, 2021

I'm going to unsubscribe from notifications as I predict this close-unclose cycle every 30 days is going to go for a while so please email me or tag me in a new issue if there is any more work or input required on this!

I'm going to try a fresh install soon (in the next 3/4 days) with those scripts.

if everything works (I don't see why it wouldn't), the I'll merge your change :)

edit: Sorry if it's taking a bit of time, we have a huge debt of issues/PRs to take care of, and we're slowly catching up ^^

@github-actions github-actions bot removed the stale label Jun 20, 2021
@SamantazFox SamantazFox marked this pull request as ready for review June 26, 2021 09:24
@SamantazFox SamantazFox added need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something and removed unfinished More work is needed on this PR, or on something this PR uses. labels Jun 26, 2021
@JuniorJPDJ
Copy link
Contributor

fixes #1772

@JuniorJPDJ
Copy link
Contributor

Hey, this MR got approved but not merged, what are we waiting for?

@syeopite
Copy link
Member

It's currently just waiting for testing. As for why it hasn't been done yet: well, we're only an small team consisting of around 5 volunteers. And there's just far too many things to do right now, so some issues/PRs are going to be sitting for a long time before we can tackle it.

@SamantazFox
Copy link
Member

Hey, this MR got approved but not merged, what are we waiting for?

Testing ^^

@JuniorJPDJ
Copy link
Contributor

I don't get why it's marked as approved without testing then >___<

I can test it a bit, as it will make me remove my dirty workaround and that would be cool.

@unixfox
Copy link
Member

unixfox commented Jul 19, 2021

I don't get why it's marked as approved without testing then >___<

I can test it a bit, as it will make me remove my dirty workaround and that would be cool.

We restrict no one from testing a PR, if you can prove that it works we can then merge it.
(A detailed proof not just "it works")

@Rjevski
Copy link
Contributor Author

Rjevski commented Jul 19, 2021 via email

@JuniorJPDJ
Copy link
Contributor

$ git clone https://github.com/iv-org/invidious.git
$ cd invidious
$ git remote add fork https://github.com/Rjevski/invidious.git
$ git fetch fork
$ git checkout idempotent-database-migrations
$ git rebase master
$ docker build -t invidious_invidious . -f docker/Dockerfile

ATM I started building container with this changes and will try to check if it still works on my prod instance (THE BEST IDEA IN MY LIFE! TEST PR ON PROD!).

To this moment I was using workaround with Dockerfile like:

$ cat Dockerfile
FROM omarroth/invidious

USER root

RUN find config/sql -iname '*.sql' -print -exec sed 's|kemal|invidious|g' -i '{}' \;

USER invidious

Where obviously invidious is my postgres username.

Later I'll try to spawn clean invidious instance without any db data.

@JuniorJPDJ
Copy link
Contributor

JuniorJPDJ commented Jul 19, 2021

Test one passed - It started without crash (version without any patching already crashed at this point AFAIR):

$ dcud
Recreating invidious_invidious_1 ... done
$ dclf
Attaching to invidious_invidious_1
invidious_1  | 2021-07-19T14:53:11.978595019Z [development] Kemal is ready to lead at http://0.0.0.0:3000

@SamantazFox
Copy link
Member

I don't get why it's marked as approved without testing then >___<

"Approved" means that the code looks good (i.e that we didn't find issues during code review). It doesn't mean that the code is working.

@SamantazFox
Copy link
Member

However my initial objective was to start a discussion and move towards a more robust migration framework - while this is a slight improvement it's still not ideal so I'm keen for us to have a better solution. I suggested using something like Alembic in the initial post.

There is something like alembic in crystal, named micrate, but given how it works, It's not really different than what we do currently (i.e manually writing migration scripts).

@JuniorJPDJ
Copy link
Contributor

"Approved" means that the code looks good (i.e that we didn't find issues during code review). It doesn't mean that the code is working.

It's pretty different approach than I already have seen in context of other projects but it's understandable ;D
Most of times "Approved" means "I'm signing those changes by my name and I admin it works and should not do any harm".

@Rjevski
Copy link
Contributor Author

Rjevski commented Jul 19, 2021 via email

@JuniorJPDJ
Copy link
Contributor

Clean install with legacy names also works:

$ cat docker-compose.yml
version: '3'
services:
  postgres:
    image: postgres
    restart: unless-stopped
    volumes:
      - ./invidious/config/sql:/config/sql
      - ./invidious/docker/init-invidious-db.sh:/docker-entrypoint-initdb.d/init-invidious-db.sh
    environment:
      POSTGRES_DB: invidious
      POSTGRES_PASSWORD: kemal
      POSTGRES_USER: kemal
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
  invidious:
    build:
      context: invidious
      dockerfile: docker/Dockerfile
    restart: unless-stopped
    networks:
      - default
      - haproxy
    environment:
      INVIDIOUS_CONFIG: |
        channel_threads: 1
        check_tables: true
        feed_threads: 1
        db:
          user: kemal
          password: kemal
          host: postgres
          port: 5432
          dbname: invidious
        full_refresh: false
        https_only: true
        domain: invidious.juniorjpdj.pl
        use_pubsub_feeds: true
        external_port: 443
        force_resolve: ipv4
        popular_enabled: true
        check_tables: true
        disable_proxy: false
        default_user_preferences:
          quality: dash
          local: true

networks:
  haproxy:
    external:
      name: haproxy
postgres_1   | 2021-07-19T16:36:39.628559649Z The files belonging to this database system will be owned by user "postgres".
postgres_1   | 2021-07-19T16:36:39.628604524Z This user must also own the server process.
postgres_1   | 2021-07-19T16:36:39.628613064Z
postgres_1   | 2021-07-19T16:36:39.628620528Z The database cluster will be initialized with locale "en_US.utf8".
postgres_1   | 2021-07-19T16:36:39.628624447Z The default database encoding has accordingly been set to "UTF8".
postgres_1   | 2021-07-19T16:36:39.628628029Z The default text search configuration will be set to "english".
postgres_1   | 2021-07-19T16:36:39.628631448Z
postgres_1   | 2021-07-19T16:36:39.628634597Z Data page checksums are disabled.
postgres_1   | 2021-07-19T16:36:39.628638621Z
postgres_1   | 2021-07-19T16:36:39.628704634Z fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres_1   | 2021-07-19T16:36:39.629203728Z creating subdirectories ... ok
postgres_1   | 2021-07-19T16:36:39.629316154Z selecting dynamic shared memory implementation ... posix
postgres_1   | 2021-07-19T16:36:39.652048275Z selecting default max_connections ... 100
postgres_1   | 2021-07-19T16:36:39.673142539Z selecting default shared_buffers ... 128MB
postgres_1   | 2021-07-19T16:36:39.688647043Z selecting default time zone ... Etc/UTC
postgres_1   | 2021-07-19T16:36:39.689906157Z creating configuration files ... ok
postgres_1   | 2021-07-19T16:36:39.826601610Z running bootstrap script ... ok
postgres_1   | 2021-07-19T16:36:40.277389070Z performing post-bootstrap initialization ... ok
postgres_1   | 2021-07-19T16:36:45.115426930Z syncing data to disk ... ok
postgres_1   | 2021-07-19T16:36:45.115451421Z
postgres_1   | 2021-07-19T16:36:45.115457785Z
postgres_1   | 2021-07-19T16:36:45.115462587Z Success. You can now start the database server using:
postgres_1   | 2021-07-19T16:36:45.115467588Z
postgres_1   | 2021-07-19T16:36:45.115472190Z     pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres_1   | 2021-07-19T16:36:45.115477127Z
postgres_1   | 2021-07-19T16:36:45.115516826Z initdb: warning: enabling "trust" authentication for local connections
postgres_1   | 2021-07-19T16:36:45.115524274Z You can change this by editing pg_hba.conf or using the option -A, or
postgres_1   | 2021-07-19T16:36:45.115529411Z --auth-local and --auth-host, the next time you run initdb.
postgres_1   | 2021-07-19T16:36:45.176463263Z waiting for server to start....2021-07-19 16:36:45.176 UTC [47] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1   | 2021-07-19T16:36:45.179968158Z 2021-07-19 16:36:45.179 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1   | 2021-07-19T16:36:45.198641194Z 2021-07-19 16:36:45.198 UTC [48] LOG:  database system was shut down at 2021-07-19 16:36:40 UTC
postgres_1   | 2021-07-19T16:36:45.208158168Z 2021-07-19 16:36:45.207 UTC [47] LOG:  database system is ready to accept connections
postgres_1   | 2021-07-19T16:36:45.234751346Z  done
postgres_1   | 2021-07-19T16:36:45.234765735Z server started
postgres_1   | 2021-07-19T16:36:46.879993276Z CREATE DATABASE
postgres_1   | 2021-07-19T16:36:46.880629842Z
postgres_1   | 2021-07-19T16:36:46.880697399Z
postgres_1   | 2021-07-19T16:36:46.880739893Z /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init-invidious-db.sh
postgres_1   | 2021-07-19T16:36:46.964993743Z CREATE ROLE
postgres_1   | 2021-07-19T16:36:47.029240306Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.033512848Z GRANT
postgres_1   | 2021-07-19T16:36:47.066062313Z CREATE INDEX
postgres_1   | 2021-07-19T16:36:47.136420824Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.144948825Z GRANT
postgres_1   | 2021-07-19T16:36:47.159549420Z CREATE INDEX
postgres_1   | 2021-07-19T16:36:47.239620862Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.247317013Z GRANT
postgres_1   | 2021-07-19T16:36:47.268106757Z CREATE INDEX
postgres_1   | 2021-07-19T16:36:47.338919392Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.342971704Z GRANT
postgres_1   | 2021-07-19T16:36:47.352005309Z CREATE INDEX
postgres_1   | 2021-07-19T16:36:47.418216842Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.422212312Z GRANT
postgres_1   | 2021-07-19T16:36:47.433741611Z CREATE INDEX
postgres_1   | 2021-07-19T16:36:47.497192491Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.502151046Z GRANT
postgres_1   | 2021-07-19T16:36:47.517147574Z CREATE INDEX
postgres_1   | 2021-07-19T16:36:47.591314859Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.597326916Z GRANT
postgres_1   | 2021-07-19T16:36:47.653149003Z CREATE TYPE
postgres_1   | 2021-07-19T16:36:47.682155662Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.692060904Z GRANT
postgres_1   | 2021-07-19T16:36:47.779854747Z CREATE TABLE
postgres_1   | 2021-07-19T16:36:47.788334799Z GRANT
postgres_1   | 2021-07-19T16:36:47.789397094Z
postgres_1   | 2021-07-19T16:36:47.790540076Z 2021-07-19 16:36:47.790 UTC [47] LOG:  received fast shutdown request
postgres_1   | 2021-07-19T16:36:47.795056214Z waiting for server to shut down....2021-07-19 16:36:47.794 UTC [47] LOG:  aborting any active transactions
postgres_1   | 2021-07-19T16:36:47.796529204Z 2021-07-19 16:36:47.796 UTC [47] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
postgres_1   | 2021-07-19T16:36:47.796883825Z 2021-07-19 16:36:47.796 UTC [49] LOG:  shutting down
postgres_1   | 2021-07-19T16:36:48.081246023Z 2021-07-19 16:36:48.081 UTC [47] LOG:  database system is shut down
postgres_1   | 2021-07-19T16:36:48.091195382Z  done
postgres_1   | 2021-07-19T16:36:48.091225601Z server stopped
postgres_1   | 2021-07-19T16:36:48.091990564Z
postgres_1   | 2021-07-19T16:36:48.092011129Z PostgreSQL init process complete; ready for start up.
postgres_1   | 2021-07-19T16:36:48.092017405Z
postgres_1   | 2021-07-19T16:36:48.126870779Z 2021-07-19 16:36:48.126 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1   | 2021-07-19T16:36:48.127434941Z 2021-07-19 16:36:48.127 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1   | 2021-07-19T16:36:48.128264922Z 2021-07-19 16:36:48.127 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1   | 2021-07-19T16:36:48.134935565Z 2021-07-19 16:36:48.134 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1   | 2021-07-19T16:36:48.144322189Z 2021-07-19 16:36:48.144 UTC [166] LOG:  database system was shut down at 2021-07-19 16:36:48 UTC
postgres_1   | 2021-07-19T16:36:48.153189400Z 2021-07-19 16:36:48.153 UTC [1] LOG:  database system is ready to accept connections
invidious_1  | 2021-07-19T16:36:48.407775482Z [development] Kemal is ready to lead at http://0.0.0.0:3000
invidious_1  | 2021-07-19T16:42:35.714239289Z 2021-07-19 16:42:35 UTC [info] 302 GET / 285.24µs
invidious_1  | 2021-07-19T16:42:40.806273577Z 2021-07-19 16:42:40 UTC [info] 200 GET /feed/popular 520.17µs
invidious_1  | 2021-07-19T16:42:41.110143145Z 2021-07-19 16:42:41 UTC [info] 200 GET /css/pure-min.css?v=fd313f0d 1.07ms
invidious_1  | 2021-07-19T16:42:41.110866449Z 2021-07-19 16:42:41 UTC [info] 200 GET /css/grids-responsive-min.css?v=fd313f0d 495.25µs
invidious_1  | 2021-07-19T16:42:41.112899534Z 2021-07-19 16:42:41 UTC [info] 200 GET /css/ionicons.min.css?v=fd313f0d 1.87ms
invidious_1  | 2021-07-19T16:42:41.113756857Z 2021-07-19 16:42:41 UTC [info] 200 GET /css/default.css?v=fd313f0d 633.47µs
invidious_1  | 2021-07-19T16:42:41.114451187Z 2021-07-19 16:42:41 UTC [info] 200 GET /js/handlers.js?v=fd313f0d 510.85µs
invidious_1  | 2021-07-19T16:42:41.114933403Z 2021-07-19 16:42:41 UTC [info] 200 GET /js/themes.js?v=fd313f0d 371.39µs
invidious_1  | 2021-07-19T16:42:41.264317121Z 2021-07-19 16:42:41 UTC [info] 200 GET /fonts/ionicons.woff2?v=4.6.3 761.47µs
invidious_1  | 2021-07-19T16:42:41.327678180Z 2021-07-19 16:42:41 UTC [info] 200 GET /apple-touch-icon.png?v=fd313f0d 356.1µs
invidious_1  | 2021-07-19T16:42:41.328137923Z 2021-07-19 16:42:41 UTC [info] 200 GET /favicon-16x16.png?v=fd313f0d 225.86µs

@JuniorJPDJ
Copy link
Contributor

Custom username and db also works:

version: '3'
services:
  postgres:
    image: postgres
    restart: unless-stopped
    volumes:
      - ./invidious/config/sql:/config/sql
      - ./invidious/docker/init-invidious-db.sh:/docker-entrypoint-initdb.d/init-invidious-db.sh
    environment:
      POSTGRES_DB: topkek_db
      POSTGRES_PASSWORD: RANDOM_PASSWORD
      POSTGRES_USER: RANDOM_NAME
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
  invidious:
    build:
      context: invidious
      dockerfile: docker/Dockerfile
    restart: unless-stopped
    networks:
      - default
      - haproxy
    depends_on:
      - postgres
    environment:
      INVIDIOUS_CONFIG: |
        channel_threads: 1
        check_tables: true
        feed_threads: 1
        db:
          user: RANDOM_NAME
          password: RANDOM_PASSWORD
          host: postgres
          port: 5432
          dbname: topkek_db
        full_refresh: false
        https_only: true
        domain: invidious.juniorjpdj.pl
        use_pubsub_feeds: true
        external_port: 443
        force_resolve: ipv4
        popular_enabled: true
        check_tables: true
        disable_proxy: false
        default_user_preferences:
          quality: dash
          local: true

networks:
  haproxy:
    external:
      name: haproxy

Log is the same as before.

@SamantazFox
Copy link
Member

@JuniorJPDJ Nice, thanks for testing. Now we have to test running the creation scripts against an exising database, and it shouldn't error out.

@JuniorJPDJ
Copy link
Contributor

It crashes on first failed command - role create:

~/invidious/docker # ./init-invidious-db.sh 
ERROR:  permission denied to create role

BTW. Do we need it anyway? What the hell is it supposed to do?

@JuniorJPDJ
Copy link
Contributor

When I removed ON_ERROR_STOP=1 from init db (line 4) it works:

-psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
+psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
~/invidious $ ./docker/init-invidious-db.sh
ERROR:  permission denied to create role
NOTICE:  relation "channels" already exists, skipping
CREATE TABLE
GRANT
NOTICE:  relation "channels_id_idx" already exists, skipping
CREATE INDEX
NOTICE:  relation "videos" already exists, skipping
CREATE TABLE
GRANT
NOTICE:  relation "id_idx" already exists, skipping
CREATE INDEX
NOTICE:  relation "channel_videos" already exists, skipping
CREATE TABLE
GRANT
NOTICE:  relation "channel_videos_ucid_idx" already exists, skipping
CREATE INDEX
NOTICE:  relation "users" already exists, skipping
CREATE TABLE
GRANT
NOTICE:  relation "email_unique_idx" already exists, skipping
CREATE INDEX
NOTICE:  relation "session_ids" already exists, skipping
CREATE TABLE
GRANT
NOTICE:  relation "session_ids_id_idx" already exists, skipping
CREATE INDEX
NOTICE:  relation "nonces" already exists, skipping
CREATE TABLE
GRANT
NOTICE:  relation "nonces_nonce_idx" already exists, skipping
CREATE INDEX
CREATE TABLE
GRANT
ERROR:  type "privacy" already exists
NOTICE:  relation "playlists" already exists, skipping
CREATE TABLE
GRANT
NOTICE:  relation "playlist_videos" already exists, skipping
CREATE TABLE
GRANT

I'm not sure if this CREATE USER postgres is supposed to be here tho.
Can someone tell me why is it here?
I asked on matrix few days ago and I got this response:
@JuniorJPDJ: why the hell it creates user postgres
@SamantazFox: That's a good question....

Link to message if anyone needs it: https://matrix.to/#/!GMIiONJMKtiqFzSxwj:snopyta.org/$162627599713uHQfp:pussthecat.org?via=snopyta.org&via=matrix.org&via=libera.chat

@JuniorJPDJ
Copy link
Contributor

Also: It shouldn't be problem anyway as script is being run only on clean DB when postgres DB container creates it. If there's existing data it won't be run by postgres container.

Would be cool to have it modified to remove ON_ERROR_STOP=1 too if that's getting removed from other calls just to be consistent.

@JuniorJPDJ
Copy link
Contributor

Also this MR should probably also modify those scripts to be run on corresponding user too:
https://github.com/iv-org/invidious/tree/master/config/migrate-scripts

@SamantazFox
Copy link
Member

It crashes on first failed command - role create:

~/invidious/docker # ./init-invidious-db.sh 
ERROR:  permission denied to create role

BTW. Do we need it anyway? What the hell is it supposed to do?

I'm not sure if this CREATE USER postgres is supposed to be here tho.
Can someone tell me why is it here?
I asked on matrix few days ago and I got this response:
@JuniorJPDJ: why the hell it creates user postgres
@SamantazFox: That's a good question....

Link to message if anyone needs it: https://matrix.to/#/!GMIiONJMKtiqFzSxwj:snopyta.org/$162627599713uHQfp:pussthecat.org?via=snopyta.org&via=matrix.org&via=libera.chat

I got the answer to that recently. This line adds a "postgres" user. It is only meant for retro-compatibility with older docker containers who had no postgres user. It probably can be removed now.

When I removed ON_ERROR_STOP=1 from init db (line 4) it works:

Ok, nice

@syeopite
Copy link
Member

syeopite commented Aug 2, 2021

There is something like alembic in crystal, named micrate, but given how it works, It's not really different than what we do currently (i.e manually writing migration scripts).

There's also https://github.com/luckyframework/avram; which is also similar to what we currently do except with .cr files and is automated. See documentation.

@syeopite
Copy link
Member

syeopite commented Oct 3, 2021

Thanks @Rjevski!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Bug] Postgres role hardcoded in initial tables
8 participants