Files
altherego/db/001_initial.sql
Aleksandr Trushkin 473953fc9c save users to sqlite
2022-05-26 12:19:47 +03:00

38 lines
935 B
PL/PgSQL

BEGIN;
CREATE TABLE IF NOT EXISTS users (
`user_id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
`chat_id` integer NOT NULL UNIQUE,
`name` VARCHAR(64) NOT NULL,
created_at datetime NOT NULL
);
CREATE TABLE IF NOT EXISTS parameters (
`param_id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
`user_id` integer NOT NULL,
`key` VARCHAR(64) NOT NULL,
`value` VARCHAR(64) NOT NULL,
FOREIGN KEY(user_id)
REFERENCES users(user_id)
ON DELETE CASCADE
);
CREATE UNIQUE INDEX IF NOT EXISTS actions_action_id_user_id_idx
ON parameters (`user_id`, `key`);
CREATE TABLE IF NOT EXISTS actions (
`action_id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
`user_id` integer NOT NULL,
`name` VARCHAR(64) NOT NULL,
FOREIGN KEY(user_id)
REFERENCES users(user_id)
ON DELETE CASCADE
);
COMMIT;
-- drop index actions_action_id_user_id_idx;
-- drop table users;
-- drop table parameters;
-- drop table actions;