feat: added stuff and corrected the schema creation.

This commit is contained in:
Leonard Excoffier
2024-08-29 21:39:57 -04:00
parent d5d823b290
commit 750d33b976
3 changed files with 35 additions and 5 deletions

View File

@@ -1,17 +1,17 @@
CREATE TABLE entities ( CREATE TABLE IF NOT EXISTS entities (
cik INT PRIMARY KEY, -- CIK is now the primary key, ensuring uniqueness cik INT PRIMARY KEY, -- CIK is now the primary key, ensuring uniqueness
name VARCHAR(255) NOT NULL -- Name of the company name VARCHAR(255) NOT NULL -- Name of the company
); );
CREATE TABLE facts ( CREATE TABLE IF NOT EXISTS facts (
id VARCHAR(255) PRIMARY KEY, -- Unique identifier for the fact id VARCHAR(255) PRIMARY KEY, -- Unique identifier for the fact
taxonomy VARCHAR(255), -- Taxonomy of the fact taxonomy VARCHAR(255), -- Taxonomy of the fact
label VARCHAR(255), -- Label of the fact label VARCHAR(255), -- Label of the fact
description TEXT, -- Description of the fact description TEXT, -- Description of the fact
unit VARCHAR(255), -- Unit of the fact unit VARCHAR(255) -- Unit of the fact
); );
CREATE TABLE data ( CREATE TABLE IF NOT EXISTS data (
cik INT, -- CIK of the company cik INT, -- CIK of the company
fact_id VARCHAR(255), fact_id VARCHAR(255),
start DATE, -- Start date of the fact start DATE, -- Start date of the fact
@@ -23,7 +23,7 @@ CREATE TABLE data (
form VARCHAR(255), form VARCHAR(255),
filed DATE, filed DATE,
frame VARCHAR(255), frame VARCHAR(255),
PRIMARY KEY (cik, label) PRIMARY KEY (cik, fact_id),
FOREIGN KEY (cik) REFERENCES entities(cik), FOREIGN KEY (cik) REFERENCES entities(cik),
FOREIGN KEY (fact_id) REFERENCES facts(id) FOREIGN KEY (fact_id) REFERENCES facts(id)
); );

29
stockdb.session.sql Normal file
View File

@@ -0,0 +1,29 @@
CREATE TABLE IF NOT EXISTS entities (
cik INT PRIMARY KEY, -- CIK is now the primary key, ensuring uniqueness
name VARCHAR(255) NOT NULL -- Name of the company
);
CREATE TABLE IF NOT EXISTS facts (
id VARCHAR(255) PRIMARY KEY, -- Unique identifier for the fact
taxonomy VARCHAR(255), -- Taxonomy of the fact
label VARCHAR(255), -- Label of the fact
description TEXT, -- Description of the fact
unit VARCHAR(255) -- Unit of the fact
);
CREATE TABLE IF NOT EXISTS data (
cik INT, -- CIK of the company
fact_id VARCHAR(255),
start DATE, -- Start date of the fact
end DATE,
val INT,
accn VARCHAR(255),
fy INT,
fp VARCHAR(255),
form VARCHAR(255),
filed DATE,
frame VARCHAR(255),
PRIMARY KEY (cik, fact_id),
FOREIGN KEY (cik) REFERENCES entities(cik),
FOREIGN KEY (fact_id) REFERENCES facts(id)
);

View File

@@ -1,3 +1,4 @@
import mariadb
import json import json
# Step 1: Load the JSON data from a file # Step 1: Load the JSON data from a file