added registry.sql and shard.sql

This commit is contained in:
celso 2026-04-02 20:21:29 -03:00
parent 52e893d75d
commit c545a1032b
2 changed files with 101 additions and 0 deletions

60
sql/registry.sql Normal file
View File

@ -0,0 +1,60 @@
CREATE DATABASE IF NOT EXISTS argent_registry;
USE argent_registry;
CREATE TABLE shards (
shard_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
db_name VARCHAR(50) NOT NULL,
host_address VARCHAR(255) NOT NULL,
port INT NOT NULL DEFAULT 53096,
);
CREATE TABLE user_shard_map (
user_id CHAR(36) PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
shard_id INT NOT NULL,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (shard_id) REFERENCES shards(shard_id)
);
CREATE TABLE cost_group_statuses (
status_id TINYINT PRIMARY KEY,
name VARCHAR(20) UNIQUE NOT NULL
);
CREATE TABLE cost_groups (
group_id CHAR(36) PRIMARY KEY,
name VARCHAR(100) NOT NULL,
created_by CHAR(36),
status_id TINYINT NOT NULL DEFAULT '1',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES user_shard_map(user_id),
FOREIGN KEY (status_id) REFERENCES cost_group_statuses(status_id)
);
CREATE TABLE group_roles (
role_id TINYINT PRIMARY KEY,
name VARCHAR(20) UNIQUE NOT NULL
);
CREATE TABLE group_members (
group_id CHAR(36),
user_id CHAR(36),
role_id TINYINT DEFAULT '3',
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (group_id, user_id),
FOREIGN KEY (group_id) REFERENCES cost_groups(group_id),
FOREIGN KEY (role_id) REFERENCES group_roles(role_id),
FOREIGN KEY (user_id) REFERENCES user_shard_map(user_id)
);
INSERT INTO cost_group_statuses (status_id, name) VALUES
(1, 'active'),
(2, 'settled'),
(3, 'archived');
INSERT INTO group_roles (role_id, name) VALUES
(1, 'owner'),
(2, 'editor'),
(3, 'participant');

41
sql/shard.sql Normal file
View File

@ -0,0 +1,41 @@
CREATE DATABASE IF NOT EXISTS argent_shard_01;
USE argent_shard_01;
CREATE TABLE ledger_statuses (
status_id TINYINT PRIMARY KEY,
name VARCHAR(20) UNIQUE NOT NULL
);
CREATE TABLE ledger (
entry_id CHAR(36) NOT NULL,
batch_id CHAR(36) NOT NULL,
user_id CHAR(36) NOT NULL,
group_id CHAR(36) DEFAULT NULL,
category_id INT,
amount DECIMAL(15, 2) NOT NULL,
currency_code CHAR(3) NOT NULL,
description VARCHAR(255),
status_id TINYINT DEFAULT '1',
created_at DATETIME NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (user_id, entry_id),
FOREIGN KEY (status_id) REFERENCES ledger_statuses(status_id),
INDEX (batch_id),
INDEX (group_id),
INDEX (status_id)
);
CREATE TABLE user_balances (
user_id CHAR(36) NOT NULL,
currency_code CHAR(3) NOT NULL,
total_confirmed DECIMAL(15, 2) DEFAULT 0.00,
total_pending DECIMAL(15, 2) DEFAULT 0.00,
PRIMARY KEY (user_id, currency_code)
);
INSERT INTO ledger_statuses (status_id, name) VALUES
(1, 'proposed'),
(2, 'ratified'),
(3, 'disputed'),
(4, 'settled');