Skip to content

Commit

Permalink
Update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
blokhin committed Jul 26, 2023
1 parent 0368835 commit 4d8afef
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions schema/schema.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@

CREATE EXTENSION IF NOT EXISTS pgcrypto;

-- Data graph nodes

CREATE TABLE IF NOT EXISTS backend_data_nodes (
item_id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
metadata jsonb,
content VARCHAR,
type SMALLINT,
item_id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
metadata jsonb NOT NULL,
content VARCHAR NOT NULL,
type SMALLINT NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
seen BOOLEAN DEFAULT FALSE
has_phase BOOLEAN DEFAULT FALSE -- TODO might want to reference the particular phase instead
);

-- Data graph edges

CREATE TABLE IF NOT EXISTS backend_data_links (
source_id UUID NOT NULL,
target_id UUID NOT NULL,
Expand All @@ -18,14 +22,29 @@ CREATE TABLE IF NOT EXISTS backend_data_links (
FOREIGN KEY (target_id) REFERENCES backend_data_nodes (item_id)
);

CREATE TABLE IF NOT EXISTS distinct_phases (
phid INT PRIMARY KEY,
elements VARCHAR(64) NOT NULL,
formula_txt VARCHAR(128) NOT NULL,
formula_html VARCHAR(384) NOT NULL,
spg INT,
pearson VARCHAR(8),
crsystem SMALLINT NOT NULL
-- Pre-defined materials phases (read-only)

CREATE TABLE IF NOT EXISTS backend_phases (
phase_id INT PRIMARY KEY,
elements VARCHAR(64) NOT NULL, -- FIXME?
formula VARCHAR(128) NOT NULL,
spg SMALLINT NOT NULL,
natcell SMALLINT NOT NULL
);

CREATE INDEX IF NOT EXISTS i_phid ON backend_phases USING btree( phase_id );
CREATE INDEX IF NOT EXISTS i_lattices ON backend_phases USING btree( spg );
CREATE INDEX IF NOT EXISTS i_elements ON backend_phases USING btree( elements text_pattern_ops );

-- Phase matching dIs

CREATE TABLE IF NOT EXISTS backend_refdis (
ext_id VARCHAR(128) NOT NULL,
phase_id INT NOT NULL,
provider SMALLINT DEFAULT 0, -- 0 Metis; 1 COD; 2 ICDD PDF4+; 3 CCDC; 4 MPDS;
elements VARCHAR(64) NOT NULL, -- FIXME?
di NUMERIC[][] NOT NULL,
FOREIGN KEY (phase_id) REFERENCES backend_phases (phase_id)
);
CREATE INDEX IF NOT EXISTS i_phid ON distinct_phases USING btree( phid );
CREATE INDEX IF NOT EXISTS i_elements ON distinct_phases USING btree( elements text_pattern_ops );

CREATE INDEX IF NOT EXISTS i_elements ON backend_refdis USING btree( elements text_pattern_ops );

0 comments on commit 4d8afef

Please sign in to comment.