From 7db7c1d755427ecf9d440596018e1b3f66c8e4f5 Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Wed, 9 Apr 2025 16:02:23 +0200 Subject: [PATCH] Altered tables and added a new table for refresh_tokens --- migrations/20250310175116_tables.sql | 35 ++++++++++++++------- migrations/20250312172645_revoked_table.sql | 6 ---- migrations/20250327145228_add_money.sql | 2 -- 3 files changed, 23 insertions(+), 20 deletions(-) delete mode 100644 migrations/20250312172645_revoked_table.sql delete mode 100644 migrations/20250327145228_add_money.sql diff --git a/migrations/20250310175116_tables.sql b/migrations/20250310175116_tables.sql index bb41825..3fc457c 100644 --- a/migrations/20250310175116_tables.sql +++ b/migrations/20250310175116_tables.sql @@ -1,21 +1,22 @@ -- Add migration script here -CREATE TABLE users ( - 'id' INTEGER PRIMARY KEY NOT NULL , +CREATE TABLE IF NOT EXISTS users ( + 'id' INTEGER PRIMARY KEY NOT NULL, 'uuid' TEXT UNIQUE NOT NULL, 'username' TEXT NOT NULL, 'hash' TEXT NOT NULL, 'email' TEXT NOT NULL ); -CREATE TABLE inventories ( - 'id' INTEGER PRIMARY KEY NOT NULL , +CREATE TABLE IF NOT EXISTS inventories ( + 'id' INTEGER PRIMARY KEY NOT NULL, 'uuid' TEXT UNIQUE NOT NULL, 'user' INTEGER NOT NULL, + 'money' FLOAT DEFAULT 0, FOREIGN KEY ('user') REFERENCES users ('id') ); -CREATE TABLE user_items ( - 'id' INTEGER PRIMARY KEY NOT NULL , +CREATE TABLE IF NOT EXISTS user_items ( + 'id' INTEGER PRIMARY KEY NOT NULL, 'uuid' TEXT UNIQUE NOT NULL, 'inventory' INTEGER NOT NULL, 'item' INTEGER NOT NULL, @@ -23,8 +24,8 @@ CREATE TABLE user_items ( FOREIGN KEY ('item') REFERENCES items ('id') ); -CREATE TABLE items ( - 'id' INTEGER PRIMARY KEY NOT NULL , +CREATE TABLE IF NOT EXISTS items ( + 'id' INTEGER PRIMARY KEY NOT NULL, 'uuid' TEXT UNIQUE NOT NULL, 'name' TEXT NOT NULL, 'rarity' INTEGER NOT NULL, @@ -32,18 +33,28 @@ CREATE TABLE items ( 'price' FLOAT NOT NULL ); -CREATE TABLE cases ( - 'id' INTEGER PRIMARY KEY NOT NULL , +CREATE TABLE IF NOT EXISTS cases ( + 'id' INTEGER PRIMARY KEY NOT NULL, 'uuid' TEXT UNIQUE NOT NULL, 'name' TEXT NOT NULL, 'image' TEXT NOT NULL, 'price' FLOAT NOT NULL ); -CREATE TABLE items_cases ( +CREATE TABLE IF NOT EXISTS items_cases ( 'item' INTEGER NOT NULL, 'case' INTEGER NOT NULL, FOREIGN KEY ('item') REFERENCES items ('id'), FOREIGN KEY ('case') REFERENCES cases ('id'), PRIMARY KEY ('item', 'case') -); \ No newline at end of file +); + +CREATE TABLE IF NOT EXISTS refresh_tokens ( +'id' INTEGER PRIMARY KEY, +'token' TEXT, +'previous' TEXT, +'user' INTEGER, +'expiry' INTEGER, +'revoked' BOOLEAN, +FOREIGN KEY ('user') REFERENCES users ('id') +); diff --git a/migrations/20250312172645_revoked_table.sql b/migrations/20250312172645_revoked_table.sql deleted file mode 100644 index d664303..0000000 --- a/migrations/20250312172645_revoked_table.sql +++ /dev/null @@ -1,6 +0,0 @@ --- Add migration script here -CREATE TABLE IF NOT EXISTS revoked ( - 'token_id' INTEGER NOT NULL, - 'user_id' VARCHAR NOT NULL, - 'expires' INTEGER NOT NULL -) \ No newline at end of file diff --git a/migrations/20250327145228_add_money.sql b/migrations/20250327145228_add_money.sql deleted file mode 100644 index ba51a98..0000000 --- a/migrations/20250327145228_add_money.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Add migration script here -ALTER TABLE inventories ADD 'money' FLOAT DEFAULT 0; \ No newline at end of file