2021-06-26 05:00:54 +02:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
2023-11-27 20:46:44 +01:00
|
|
|
"context"
|
2021-06-26 05:00:54 +02:00
|
|
|
"database/sql"
|
|
|
|
|
2023-04-04 15:57:00 +02:00
|
|
|
"github.com/pressly/goose/v3"
|
2021-06-26 05:00:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2023-11-27 20:46:44 +01:00
|
|
|
goose.AddMigrationContext(upAddReferentialIntegrityToUserProps, downAddReferentialIntegrityToUserProps)
|
2021-06-26 05:00:54 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 20:46:44 +01:00
|
|
|
func upAddReferentialIntegrityToUserProps(_ context.Context, tx *sql.Tx) error {
|
2021-06-26 05:00:54 +02:00
|
|
|
_, 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 {
|
2021-06-26 05:00:54 +02:00
|
|
|
return nil
|
|
|
|
}
|