chore: add down migrations

This commit is contained in:
sam 2023-08-16 03:30:34 +02:00
parent b826fb3ce6
commit 0c2eeaf954
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
19 changed files with 191 additions and 36 deletions

View File

@ -1,7 +1,7 @@
-- +migrate Up
-- 2022-05-02: initial schema
-- +migrate Up
create table users (
id text primary key,
username text not null unique,
@ -89,3 +89,16 @@ create table invites (
created timestamp not null default (current_timestamp at time zone 'utc'),
used boolean not null default false
);
-- +migrate Down
drop table invites;
drop table member_fields;
drop table member_pronouns;
drop table member_names;
drop index members_user_name_idx;
drop table members;
drop table user_fields;
drop table user_pronouns;
drop table user_names;
drop table users;

View File

@ -1,4 +1,9 @@
-- 2022-11-20: add display name to members
-- +migrate Up
-- 2022-11-20: add display name to members
alter table members add column display_name text;
-- +migrate Down
alter table members drop column display_name;

View File

@ -1,6 +1,7 @@
-- 2022-12-23: Add database-backed tokens
-- +migrate Up
-- 2022-12-23: Add database-backed tokens
create table tokens (
user_id text not null references users (id) on delete cascade,
token_id text primary key,
@ -13,3 +14,9 @@ create table tokens (
-- This does not change anything code-wise, but it's recommended over plain timestamp because plain timestamp does not handle timezones correctly
alter table invites alter column created type timestamptz;
alter table invites alter column created set default now();
-- +migrate Down
drop table tokens;
alter table invites alter column created type timestamp;
alter table invites alter column created set default (current_timestamp at time zone 'utc');

View File

@ -1,7 +1,7 @@
-- +migrate Up
-- 2023-01-03: change names, pronouns, and fields to be columns instead of separate tables
-- +migrate Up
create type field_entry as (
value text,
status int
@ -33,3 +33,29 @@ alter table member_fields drop column okay;
alter table member_fields drop column jokingly;
alter table member_fields drop column friends_only;
alter table member_fields drop column avoid;
-- +migrate Down
alter table user_fields add column favourite text[];
alter table user_fields add column okay text[];
alter table user_fields add column jokingly text[];
alter table user_fields add column friends_only text[];
alter table user_fields add column avoid text[];
alter table member_fields add column favourite text[];
alter table member_fields add column okay text[];
alter table member_fields add column jokingly text[];
alter table member_fields add column friends_only text[];
alter table member_fields add column avoid text[];
alter table users drop column names;
alter table users drop column pronouns;
alter table members drop column names;
alter table members drop column pronouns;
alter table user_fields drop column entries;
alter table member_fields drop column entries;
drop type field_entry;
drop type pronoun_entry;

View File

@ -1,10 +1,16 @@
-- +migrate Up
-- 2023-03-07: add delete functionality
-- +migrate Up
-- if not null, the user is soft deleted
alter table users add column deleted_at timestamptz;
-- if true, the user deleted their account themselves + should have option to reactivate; should also be deleted after 30 days
alter table users add column self_delete boolean;
-- delete reason if the user was deleted by a moderator
alter table users add column delete_reason text;
-- +migrate Down
alter table users drop column deleted_at;
alter table users drop column self_delete;
alter table users drop column delete_reason;

View File

@ -1,8 +1,8 @@
-- +migrate Up
-- 2023-03-11: Change composite type arrays to use jsonb columns
-- Composite types aren't actually supported by pgx and this allows us to drop pggen as a dev dependency.
-- +migrate Up
-- Delete old columns
alter table users drop column names;
alter table users drop column pronouns;
@ -22,3 +22,25 @@ alter table members add column pronouns jsonb not null default '[]';
alter table user_fields add column entries jsonb not null default '[]';
alter table member_fields add column entries jsonb not null default '[]';
-- +migrate Down
-- Delete old columns
alter table users drop column names;
alter table users drop column pronouns;
alter table members drop column names;
alter table members drop column pronouns;
alter table user_fields drop column entries;
alter table member_fields drop column entries;
-- Create new columns
alter table users add column names field_entry;
alter table users add column pronouns pronoun_entry;
alter table members add column names field_entry;
alter table members add column pronouns pronoun_entry;
alter table user_fields add column entries field_entry;
alter table member_fields add column entries field_entry;

View File

@ -1,9 +1,17 @@
-- +migrate Up
-- 2023-03-13: Change avatar URLs to hashes
-- +migrate Up
alter table users drop column avatar_urls;
alter table members drop column avatar_urls;
alter table users add column avatar text;
alter table members add column avatar text;
-- +migrate Down
alter table users drop column avatar;
alter table members drop column avatar;
alter table users add column avatar_urls text[];
alter table members add column avatar_urls text[];

View File

@ -1,10 +1,14 @@
-- +migrate Up
-- 2023-03-15: Add data export
-- +migrate Up
create table data_exports (
id serial primary key,
user_id text not null references users (id) on delete cascade,
filename text not null,
created_at timestamptz not null default now()
);
-- +migrate Down
drop table data_exports;

View File

@ -1,7 +1,7 @@
-- +migrate Up
-- 2023-03-16: Add fediverse (Mastodon/Pleroma/Misskey) OAuth
-- +migrate Up
create table fediverse_apps (
id serial primary key,
instance text not null unique,
@ -13,3 +13,11 @@ create table fediverse_apps (
alter table users add column fediverse text null;
alter table users add column fediverse_username text null;
alter table users add column fediverse_app_id integer null references fediverse_apps (id) on delete set null;
-- +migrate Down
alter table users drop column fediverse;
alter table users drop column fediverse_username;
alter table users drop column fediverse_app_id;
drop table fediverse_apps;

View File

@ -1,7 +1,7 @@
-- +migrate Up
-- 2023-03-19: Add moderation-related tables
-- +migrate Up
alter table users add column is_admin boolean not null default false;
create table reports (
@ -25,3 +25,9 @@ create table warnings (
created_at timestamptz not null default now(),
read_at timestamptz
);
-- +migrate Down
drop table warnings;
drop table reports;
alter table users drop column is_admin;

View File

@ -1,6 +1,11 @@
-- +migrate Up
-- 2023-03-30: Add token information to database
-- +migrate Up
alter table tokens add column api_only boolean not null default false;
alter table tokens add column read_only boolean not null default false;
-- +migrate Down
alter table tokens drop column api_only;
alter table tokens drop column read_only;

View File

@ -1,8 +1,15 @@
-- +migrate Up
-- 2023-04-01: Add a couple customization options to users and members
-- +migrate Up
alter table users add column member_title text;
alter table users add column list_private boolean not null default false;
alter table members add column unlisted boolean not null default false;
-- +migrate Down
alter table users drop column member_title;
alter table users drop column list_private;
alter table members drop column unlisted;

View File

@ -1,6 +1,11 @@
-- +migrate Up
-- 2023-04-18: Add tumblr oauth
-- +migrate Up
alter table users add column tumblr text null;
alter table users add column tumblr_username text null;
-- +migrate Down
alter table users drop column tumblr;
alter table users drop column tumblr_username;

View File

@ -1,6 +1,11 @@
-- +migrate Up
-- 2023-04-18: Add Google oauth
-- +migrate Up
alter table users add column google text null;
alter table users add column google_username text null;
-- +migrate Down
alter table users drop column google;
alter table users drop column google_username;

View File

@ -1,5 +1,9 @@
-- +migrate Up
-- 2023-04-19: Add custom preferences
-- +migrate Up
alter table users add column custom_preferences jsonb not null default '{}';
-- +migrate Down
alter table users drop column custom_preferences;

View File

@ -1,7 +1,11 @@
-- +migrate Up
-- 2023-05-02: Add a last_active column to users, updated whenever the user modifies their profile or members.
-- This is not directly exposed in the API.
-- Potential future use cases: showing total number of active users, pruning completely empty users if they don't log in?
-- +migrate Up
alter table users add column last_active timestamptz not null default now();
-- +migrate Down
alter table users drop column last_active;

View File

@ -1,8 +1,8 @@
-- +migrate Up
-- 2023-05-09: Add pride flags
-- Hashes are a separate table so we can deduplicate flags.
-- +migrate Up
create table pride_flags (
id text primary key,
user_id text not null references users (id) on delete cascade,
@ -22,3 +22,9 @@ create table member_flags (
member_id text not null references members (id) on delete cascade,
flag_id text not null references pride_flags (id) on delete cascade
);
-- +migrate Down
drop table member_flags;
drop table user_flags;
drop table pride_flags;

View File

@ -1,7 +1,7 @@
-- +migrate Up
-- 2023-06-03: Add short IDs for the prns.cc domain.
-- +migrate Up
-- add the columns
alter table users add column sid text unique check(length(sid)=5);
alter table members add column sid text unique check(length(sid)=6);
@ -48,3 +48,13 @@ update members set sid = find_free_member_sid();
-- finally, make the values non-nullable
alter table users alter column sid set not null;
alter table members alter column sid set not null;
-- +migrate Down
drop function find_free_member_sid;
drop function find_free_user_sid;
drop function generate_sid;
alter table users drop column sid;
alter table users drop column last_sid_reroll;
alter table members drop column sid;

View File

@ -1,5 +1,9 @@
-- +migrate Up
-- 2023-07-30: Add user timezones
-- +migrate Up
alter table users add column timezone text null;
-- +migrate Down
alter table users drop column timezone;