fix: correctly set primary key for data table

This commit is contained in:
Leonard Excoffier
2024-08-30 07:56:02 -04:00
parent 0f9a42eb7e
commit 184f82a688
2 changed files with 3 additions and 32 deletions

View File

@@ -13,9 +13,9 @@ CREATE TABLE IF NOT EXISTS facts (
CREATE TABLE IF NOT EXISTS data (
cik INT, -- CIK of the company
fact_id VARCHAR(255),
fact_id VARCHAR(255),
end DATE,
start DATE, -- Start date of the fact
end DATE,
val INT,
accn VARCHAR(255),
fy INT,
@@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS data (
form VARCHAR(255),
filed DATE,
frame VARCHAR(255),
PRIMARY KEY (cik, fact_id),
PRIMARY KEY (cik, fact_id, end),
FOREIGN KEY (cik) REFERENCES entities(cik),
FOREIGN KEY (fact_id) REFERENCES facts(id)
);

View File

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