From d10f0a2881d34ea801166e158bc1eaa3db9c28e3 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Wed, 10 Nov 2021 09:53:24 -0800 Subject: [PATCH] Implement the down migration for personal projects --- .../2021-11-06T033930Z_PersonalProjects.go | 24 ++++++++++++++++++- src/migration/migrations/migrations.go | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/migration/migrations/2021-11-06T033930Z_PersonalProjects.go b/src/migration/migrations/2021-11-06T033930Z_PersonalProjects.go index b07b286d..53da300c 100644 --- a/src/migration/migrations/2021-11-06T033930Z_PersonalProjects.go +++ b/src/migration/migrations/2021-11-06T033930Z_PersonalProjects.go @@ -77,5 +77,27 @@ func (m PersonalProjects) Up(ctx context.Context, tx pgx.Tx) error { } func (m PersonalProjects) Down(ctx context.Context, tx pgx.Tx) error { - panic("Implement me") + var err error + + _, err = tx.Exec(ctx, ` + ALTER TABLE handmade_project + DROP CONSTRAINT slug_syntax, + DROP CONSTRAINT tag_syntax, + DROP personal, + DROP tag, + ADD featurevotes INT NOT NULL DEFAULT 0, + -- no projects actually have a parent id so thankfully no further updates to do + ADD parent_id INT REFERENCES handmade_project (id) ON DELETE SET NULL, + ADD quota INT NOT NULL DEFAULT 0, + ADD quota_used INT NOT NULL DEFAULT 0, + ADD standalone BOOLEAN NOT NULL DEFAULT FALSE, + ALTER hidden TYPE INT USING CASE WHEN hidden THEN 1 ELSE 0 END; + + ALTER TABLE handmade_project RENAME hidden TO flags; + `) + if err != nil { + return oops.New(err, "failed to revert personal project changes") + } + + return nil } diff --git a/src/migration/migrations/migrations.go b/src/migration/migrations/migrations.go index ca33045e..0805b909 100644 --- a/src/migration/migrations/migrations.go +++ b/src/migration/migrations/migrations.go @@ -8,7 +8,7 @@ import ( "github.com/jackc/pgx/v4" ) -var All map[types.MigrationVersion]types.Migration = make(map[types.MigrationVersion]types.Migration) +var All = make(map[types.MigrationVersion]types.Migration) func registerMigration(m types.Migration) { All[m.Version()] = m