generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschema.sql
68 lines (65 loc) · 1.87 KB
/
schema.sql
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
-- Declare a variable to store the entity_schema value
DO $$
DECLARE
schema_name TEXT;
BEGIN
-- Retrieve the entity_schema value using the SELECT query
SELECT information.schema_name
INTO schema_name
FROM information_schema.schemata as information
WHERE information.schema_name LIKE 'dcl' || '%'
ORDER BY CAST(SUBSTRING(information.schema_name FROM 'dcl([0-9]+)') AS INTEGER)
desc LIMIT 1;
-- Set the current working schema using the retrieved entity_schema value
EXECUTE 'SET search_path TO ' || schema_name;
-- Output the current working schema
RAISE NOTICE 'Current working schema set to: %', schema_name;
END $$;
CREATE TABLE collections (
id TEXT NOT NULL PRIMARY KEY,
creator TEXT NOT NULL,
is_approved BOOLEAN NOT NULL DEFAULT false,
name TEXT NOT NULL,
symbol TEXT NOT NULL,
owner TEXT NOT NULL,
is_completed BOOLEAN NOT NULL DEFAULT false,
created_at INTEGER NOT NULL
);
create TABLE items (
id TEXT NOT NULL PRIMARY KEY,
blockchain_item_id BigInt NOT NULL,
item_type TEXT NOT NULL,
price TEXT NOT NULL,
total_supply TEXT NOT NULL,
available TEXT NOT NULL,
max_supply TEXT NOT NULL,
rarity TEXT NOT NULL,
beneficiary TEXT NOT NULL,
raw_metadata TEXT NOT NULL,
collection_id TEXT NOT NULL,
created_at INTEGER NOT NULL -- CONSTRAINT fk_collection FOREIGN KEY(collection_id) REFERENCES collections(id)
);
CREATE TABLE orders (
id TEXT NOT NULL PRIMARY KEY,
marketplace_address TEXT NOT NULL,
nft_id TEXT NOT NULL,
token_id TEXT NOT NULL,
tx_hash TEXT NOT NULL,
owner TEXT NOT NULL,
buyer TEXT,
price TEXT NOT NULL,
status TEXT NOT NULL,
block_number TEXT NOT NULL,
expires_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
CREATE TABLE nfts (
id TEXT NOT NULL PRIMARY KEY,
token_id TEXT NOT NULL,
collection_id TEXT NOT NULL,
issued_id TEXT NOT NULL,
item_id TEXT NOT NULL,
owner TEXT NOT NULL,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);