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
| -- Partie un
CREATE TABLE foo(
fooId PRIMARY KEY,
createdAt timestamp with time zone NOT NULL DEFAULT CURRENT_DATE,
updatedAt timestamp with time zone,
uuid text NOT NULL,
autresChamps [...]
)
CREATE TABLE bar(
barId PRIMARY KEY,
fooId integer REFERENCES foo(fooId),
infoOne text NOT NULL,
autresChamps [...]
)
CREATE TABLE baz(
bazId PRIMARY KEY,
fooId integer REFERENCES foo(fooId),
name text NOT NULL,
infoTwo boolean DEFAULT FALSE,
autresChamps [...]
)
-- other related table
-- Partie deux
CREATE TABLE qux(
quxId PRIMARY KEY,
createdAt timestamp with time zone NOT NULL DEFAULT CURRENT_DATE,
updatedAt timestamp with time zone,
name test NOT NULL,
infoOne boolean DEFAULT FALSE,
autresChamps [...]
)
CREATE TABLE fum(
fumId PRIMARY KEY,
quxId integer REFERENCES qux(quxId),
infoOne text NOT NULL,
autresChamps [...],
)
-- other related table
-- lien entre les deux "parties"
CREATE TABLE linked(
fooId integer REFERENCES foo(fooId),
quxId integer REFERENCES qux(quxId),
autresChamps [...],
PRIMARY KEY (fooId, quxId)
) |
Partager