navidrome/db/migrations/20210625223901_add_referent...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
854 B
Go
Raw Normal View History

package migrations
import (
2023-11-27 20:46:44 +01:00
"context"
"database/sql"
2023-04-04 15:57:00 +02:00
"github.com/pressly/goose/v3"
)
func init() {
2023-11-27 20:46:44 +01:00
goose.AddMigrationContext(upAddReferentialIntegrityToUserProps, downAddReferentialIntegrityToUserProps)
}
2023-11-27 20:46:44 +01:00
func upAddReferentialIntegrityToUserProps(_ context.Context, tx *sql.Tx) error {
_, err := tx.Exec(`
create table user_props_dg_tmp
(
user_id varchar not null
constraint user_props_user_id_fk
references user
on update cascade on delete cascade,
key varchar not null,
value varchar,
constraint user_props_pk
primary key (user_id, key)
);
insert into user_props_dg_tmp(user_id, key, value) select user_id, key, value from user_props;
drop table user_props;
alter table user_props_dg_tmp rename to user_props;
`)
return err
}
2023-11-27 20:46:44 +01:00
func downAddReferentialIntegrityToUserProps(_ context.Context, tx *sql.Tx) error {
return nil
}