2022-07-08 17:16:18 +03:00
|
|
|
-- change user role field from "OWNER"/"USER" to "HOST"/"USER".
|
|
|
|
PRAGMA foreign_keys = off;
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS _user_old;
|
|
|
|
|
2023-01-22 16:16:03 +03:00
|
|
|
ALTER TABLE
|
|
|
|
user RENAME TO _user_old;
|
2022-07-08 17:16:18 +03:00
|
|
|
|
|
|
|
CREATE TABLE user (
|
2023-01-22 16:16:03 +03:00
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
|
|
|
|
email TEXT NOT NULL UNIQUE,
|
|
|
|
role TEXT NOT NULL CHECK (role IN ('HOST', 'USER')) DEFAULT 'USER',
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
password_hash TEXT NOT NULL,
|
2022-07-08 17:16:18 +03:00
|
|
|
open_id TEXT NOT NULL UNIQUE
|
|
|
|
);
|
|
|
|
|
2023-01-22 16:16:03 +03:00
|
|
|
INSERT INTO
|
|
|
|
user (
|
|
|
|
id,
|
|
|
|
created_ts,
|
|
|
|
updated_ts,
|
|
|
|
row_status,
|
|
|
|
email,
|
|
|
|
name,
|
|
|
|
password_hash,
|
|
|
|
open_id
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
id,
|
|
|
|
created_ts,
|
|
|
|
updated_ts,
|
|
|
|
row_status,
|
|
|
|
email,
|
|
|
|
name,
|
|
|
|
password_hash,
|
|
|
|
open_id
|
|
|
|
FROM
|
2022-07-08 17:16:18 +03:00
|
|
|
_user_old;
|
|
|
|
|
2023-01-22 16:16:03 +03:00
|
|
|
UPDATE
|
|
|
|
user
|
|
|
|
SET
|
|
|
|
role = 'HOST'
|
|
|
|
WHERE
|
2022-07-08 17:16:18 +03:00
|
|
|
id IN (
|
2023-01-22 16:16:03 +03:00
|
|
|
SELECT
|
|
|
|
id
|
|
|
|
FROM
|
|
|
|
_user_old
|
|
|
|
WHERE
|
2022-07-08 17:16:18 +03:00
|
|
|
role = 'OWNER'
|
|
|
|
);
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS _user_old;
|
|
|
|
|
2023-01-22 16:16:03 +03:00
|
|
|
PRAGMA foreign_keys = on;
|