2020-10-15 18:09:41 +01:00
|
|
|
package deltas
|
|
|
|
|
|
|
|
import (
|
2022-07-25 10:39:22 +01:00
|
|
|
"context"
|
2020-10-15 18:09:41 +01:00
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2022-07-25 10:39:22 +01:00
|
|
|
func UpIsActive(ctx context.Context, tx *sql.Tx) error {
|
|
|
|
_, err := tx.ExecContext(ctx, `
|
2022-10-18 15:59:08 +01:00
|
|
|
ALTER TABLE userapi_accounts RENAME TO userapi_accounts_tmp;
|
|
|
|
CREATE TABLE userapi_accounts (
|
2020-10-15 18:09:41 +01:00
|
|
|
localpart TEXT NOT NULL PRIMARY KEY,
|
2022-11-11 16:41:37 +00:00
|
|
|
server_name TEXT NOT NULL,
|
2020-10-15 18:09:41 +01:00
|
|
|
created_ts BIGINT NOT NULL,
|
|
|
|
password_hash TEXT,
|
|
|
|
appservice_id TEXT,
|
|
|
|
is_deactivated BOOLEAN DEFAULT 0
|
|
|
|
);
|
|
|
|
INSERT
|
2022-10-18 15:59:08 +01:00
|
|
|
INTO userapi_accounts (
|
2020-10-15 18:09:41 +01:00
|
|
|
localpart, created_ts, password_hash, appservice_id
|
|
|
|
) SELECT
|
|
|
|
localpart, created_ts, password_hash, appservice_id
|
2022-10-18 15:59:08 +01:00
|
|
|
FROM userapi_accounts_tmp
|
2020-10-15 18:09:41 +01:00
|
|
|
;
|
2022-10-18 15:59:08 +01:00
|
|
|
DROP TABLE userapi_accounts_tmp;`)
|
2020-10-15 18:09:41 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to execute upgrade: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-25 10:39:22 +01:00
|
|
|
func DownIsActive(ctx context.Context, tx *sql.Tx) error {
|
|
|
|
_, err := tx.ExecContext(ctx, `
|
2022-10-18 15:59:08 +01:00
|
|
|
ALTER TABLE userapi_accounts RENAME TO userapi_accounts_tmp;
|
|
|
|
CREATE TABLE userapi_accounts (
|
2020-10-15 18:09:41 +01:00
|
|
|
localpart TEXT NOT NULL PRIMARY KEY,
|
|
|
|
created_ts BIGINT NOT NULL,
|
|
|
|
password_hash TEXT,
|
|
|
|
appservice_id TEXT
|
|
|
|
);
|
|
|
|
INSERT
|
2022-10-18 15:59:08 +01:00
|
|
|
INTO userapi_accounts (
|
2020-10-15 18:09:41 +01:00
|
|
|
localpart, created_ts, password_hash, appservice_id
|
|
|
|
) SELECT
|
|
|
|
localpart, created_ts, password_hash, appservice_id
|
2022-10-18 15:59:08 +01:00
|
|
|
FROM userapi_accounts_tmp
|
2020-10-15 18:09:41 +01:00
|
|
|
;
|
2022-10-18 15:59:08 +01:00
|
|
|
DROP TABLE userapi_accounts_tmp;`)
|
2020-10-15 18:09:41 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to execute downgrade: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|