-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
91 lines (59 loc) · 2.17 KB
/
schema.sql
File metadata and controls
91 lines (59 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
-- postgresql build script!
/* CREATE DATABASE myfacts_db;
CREATE USER myfacts_app WITH PASSWORD 'dev'; */
drop table current_facts_int;
drop table current_facts_text;
drop table current_facts;
drop table retractions;
drop table facts_int;
drop table facts_text;
drop table facts;
drop table entities;
drop table transactions;
drop table properties;
drop sequence serial;
CREATE SEQUENCE serial START 1;
create table properties ( -- should this be called attributes?
pid bigint DEFAULT nextval('serial') primary key not null,
type text not null,
-- should the property namespace be an entity type?
-- rather than being a prefix portion of a string?
-- entity_type_id int not null?
-- or perhaps called context? namespace?
name text not null
);
-- do we need an entity_types table?
create table entities (
eid bigint DEFAULT nextval('serial') primary key not null,
type text not null, -- potenially an array of names?
meta text not null
);
create table transactions (
tid bigint DEFAULT nextval('serial') primary key not null,
-- system_time when a fact was recorded
-- domain_time when a fact was actually known, created, or happened
meta text not null
);
create table facts (
fid bigint DEFAULT nextval('serial') primary key not null,
tid bigint not null references transactions,
eid bigint not null references entities,
pid bigint not null references properties
);
create table facts_text (value text not null) inherits (facts);
create table facts_int (value int not null) inherits (facts);
create table retractions (
rid bigint DEFAULT nextval('serial') primary key not null,
tid bigint not null references transactions,
eid bigint not null references entities,
pid bigint not null references properties
);
-- removals? deletions? excisions?
create table current_facts (
cfid bigint DEFAULT nextval('serial') primary key not null,
eid bigint not null references entities,
pid bigint not null references properties
);
create table current_facts_text ( value text not null ) inherits (current_facts);
create table current_facts_int ( value int not null ) inherits (current_facts);
--