From 8e32b074665b3b80e89b6cd62ea67c284f2bb567 Mon Sep 17 00:00:00 2001 From: Ske Date: Tue, 28 Jul 2020 19:41:17 +0200 Subject: [PATCH] Move legacy migration docs to a separate file and reword --- LEGACYMIGRATE.md | 37 +++++++++++++++++++++++++++++++++++++ README.md | 26 ++------------------------ 2 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 LEGACYMIGRATE.md diff --git a/LEGACYMIGRATE.md b/LEGACYMIGRATE.md new file mode 100644 index 00000000..a08c3b82 --- /dev/null +++ b/LEGACYMIGRATE.md @@ -0,0 +1,37 @@ +# Legacy bot migration +Until the introduction of the database migration system around December 2019, migrations were done manually. + +To bridge the gap between the `legacy` branch's database schema and something the modern migration system can work with, run the following SQL commands on the database: + +```sql +-- Create the proxy_tag type +do $$ begin + create type proxy_tag as ( + prefix text, + suffix text + ); +exception when duplicate_object then null; +end $$; + +-- Add new columns to `members` +alter table members add column IF NOT EXISTS display_name text; +alter table members add column IF NOT EXISTS proxy_tags proxy_tag[] not null default array[]::proxy_tag[]; +alter table members add column IF NOT EXISTS keep_proxy bool not null default false; + +-- Transfer member proxy tags from the `prefix` and `suffix` columns to the `proxy_tags` array +update members set proxy_tags = array[(members.prefix, members.suffix)]::proxy_tag[] + where members.prefix is not null or members.suffix is not null; + +-- Add other columns +alter table messages add column IF NOT EXISTS original_mid bigint; +alter table servers add column IF NOT EXISTS log_blacklist bigint[] not null default array[]::bigint[]; +alter table servers add column IF NOT EXISTS blacklist bigint[] not null default array[]::bigint[]; + +-- Drop old proxy tag columns +alter table members drop column IF EXISTS prefix cascade; +alter table members drop column IF EXISTS suffix cascade; +``` + +You should probably take a database backup before doing any of this. + +The .NET version of the bot should pick up on any further migrations from this point :) \ No newline at end of file diff --git a/README.md b/README.md index 0ad45e91..1c750a17 100644 --- a/README.md +++ b/README.md @@ -55,30 +55,8 @@ $ docker-compose up -d (tip: use `scripts/run-test-db.sh` to run a temporary PostgreSQL database on your local system. Requires Docker.) # Upgrading database from legacy version -There are a few adjustments to do for the new versions of PluralKit to work with a legacy PluralKit database : - -* Dump the database (you never know what may happen !) -* Upgrade the database by firing those lines in psql (or by putting them in an sql file and giving it to postgres) : -```sql -do $$ begin - create type proxy_tag as ( - prefix text, - suffix text - ); -exception when duplicate_object then null; -end $$; - -alter table members add column IF NOT EXISTS display_name text; -alter table members add column IF NOT EXISTS proxy_tags proxy_tag[] not null default array[]::proxy_tag[]; -alter table members add column IF NOT EXISTS keep_proxy bool not null default false; -update members set proxy_tags = array[(members.prefix, members.suffix)]::proxy_tag[] where members.prefix is not null or members.suffix is not null; -alter table members drop column IF EXISTS prefix cascade; -alter table members drop column IF EXISTS suffix cascade; -alter table messages add column IF NOT EXISTS original_mid bigint; -alter table servers add column IF NOT EXISTS log_blacklist bigint[] not null default array[]::bigint[]; -alter table servers add column IF NOT EXISTS blacklist bigint[] not null default array[]::bigint[]; -``` -* Start PluralKit and let it finish the automatic database upgrades +If you have an instance of the Python version of the bot (from the `legacy` branch), you may need to take extra database migration steps. +For more information, see [LEGACYMIGRATE.md](./LEGACYMIGRATE.md). # Documentation See [the docs/ directory](./docs/README.md)