some ideas about database structure, began assets fetching request

This commit is contained in:
Blue 2024-01-11 18:33:46 -03:00
parent a1ab1339e3
commit d33ec5def8
Signed by: blue
GPG key ID: 9B203B252A63EE38
13 changed files with 251 additions and 45 deletions

View file

@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS roleBindings (
--creating sessings table
CREATE TABLE IF NOT EXISTS sessions (
`id` INTEGER AUTO_INCREMENT PRIMARY KEY,
`id` INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`owner` INTEGER UNSIGNED NOT NULL,
`started` TIMESTAMP DEFAULT UTC_TIMESTAMP(),
`latest` TIMESTAMP DEFAULT UTC_TIMESTAMP(),
@ -45,13 +45,90 @@ CREATE TABLE IF NOT EXISTS sessions (
FOREIGN KEY (owner) REFERENCES accounts(id)
);
--creating currencies table
CREATE TABLE IF NOT EXISTS currencies (
`id` INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`code` VARCHAR(16) NOT NULL UNIQUE,
`title` VARCHAR(256),
`manual` BOOLEAN NOT NULL,
`added` TIMESTAMP DEFAULT UTC_TIMESTAMP(),
`type` INTEGER UNSIGNED NOT NULL,
`value` DECIMAL (20, 5) NOT NULL,
`source` TEXT,
`description` TEXT,
INDEX manual_idx (manual)
);
--creating assests table
CREATE TABLE IF NOT EXISTS assets (
`id` INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`owner` INTEGER UNSIGNED NOT NULL,
`currency` INTEGER UNSIGNED NOT NULL,
`title` VARCHAR(256),
`icon` VARCHAR(256),
`color` INTEGER UNSIGNED DEFAULT 0,
`balance` DECIMAL (20, 5) DEFAULT 0,
`type` INTEGER UNSIGNED NOT NULL,
`archived` BOOLEAN DEFAULT FALSE,
INDEX owner_idx (owner),
INDEX archived_idx (archived),
FOREIGN KEY (owner) REFERENCES accounts(id),
FOREIGN KEY (currency) REFERENCES currencies(id)
);
--creating parties table
CREATE TABLE IF NOT EXISTS parties (
`id` INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(256) NOT NULL UNIQUE
);
--creating transactions table
CREATE TABLE IF NOT EXISTS transactions (
`id` INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`initiator` INTEGER UNSIGNED NOT NULL,
`type` INTEGER UNSIGNED NOT NULL,
`asset` INTEGER UNSIGNED NOT NULL,
`parent` INTEGER UNSIGNED,
`value` DECIMAL (20, 5) NOT NULL,
`state` INTEGER UNSIGNED DEFAULT 0,
`modified` TIMESTAMP DEFAULT UTC_TIMESTAMP(),
`performed` TIMESTAMP DEFAULT UTC_TIMESTAMP(),
`party` INTEGER UNSIGNED,
`notes` TEXT,
INDEX initiator_idx (initiator),
INDEX parent_idx (parent),
INDEX asset_idx (asset),
INDEX performed_idx (performed),
INDEX modified_idx (modified),
INDEX party_idx (party),
FOREIGN KEY (initiator) REFERENCES accounts(id),
FOREIGN KEY (asset) REFERENCES assets(id),
FOREIGN KEY (parent) REFERENCES transactions(id),
FOREIGN KEY (party) REFERENCES parties(id)
);
--creating defailt roles
INSERT IGNORE INTO roles (`name`)
INSERT IGNORE INTO
roles (`name`)
VALUES ('root'),
('default');
--inserting initial version
INSERT INTO system (`key`, `value`) VALUES ('version', '0');
INSERT IGNORE INTO
system (`key`, `value`)
VALUES ('version', '0');
--recording initial time
INSERT INTO system (`key`, `value`) VALUES ('created', UTC_TIMESTAMP());
INSERT IGNORE INTO
system (`key`, `value`)
VALUES ('created', UTC_TIMESTAMP());
--creating default currencies
INSERT IGNORE INTO
currencies (`code`, `title`, `manual`, `description`, `type`, `value`)
VALUES ('USD', 'United States Dollar', TRUE, 'Base currency', 0, 1);