Implement the down migration for personal projects

This commit is contained in:
Ben Visness 2021-11-10 09:53:24 -08:00
parent c8373aae81
commit 5f7dedce93
2 changed files with 24 additions and 2 deletions

View File

@ -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
}

View File

@ -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