save users to sqlite

This commit is contained in:
Aleksandr Trushkin
2022-05-26 12:19:47 +03:00
parent d83af3e6cd
commit 473953fc9c
11 changed files with 1528 additions and 468 deletions

37
db/001_initial.sql Normal file
View File

@ -0,0 +1,37 @@
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;