Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

meta-schema.sql 1.5 KB

You have to be logged in to leave a comment. Sign In
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
  1. --- Schema for tables tracking the import process and related metadata
  2. CREATE TABLE IF NOT EXISTS stage_status (
  3. stage_name VARCHAR PRIMARY KEY,
  4. started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  5. finished_at TIMESTAMP NULL,
  6. stage_key VARCHAR NULL
  7. );
  8. CREATE TABLE IF NOT EXISTS source_file (
  9. filename VARCHAR NOT NULL PRIMARY KEY,
  10. reg_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  11. checksum VARCHAR NOT NULL
  12. );
  13. CREATE TABLE IF NOT EXISTS stage_file (
  14. stage_name VARCHAR NOT NULL REFERENCES stage_status,
  15. filename VARCHAR NOT NULL REFERENCES source_file,
  16. checksum VARCHAR NULL,
  17. PRIMARY KEY (stage_name, filename)
  18. );
  19. CREATE TABLE IF NOT EXISTS stage_dep (
  20. stage_name VARCHAR NOT NULL REFERENCES stage_status,
  21. dep_name VARCHAR NOT NULL REFERENCES stage_status,
  22. dep_key VARCHAR NULL
  23. );
  24. CREATE TABLE IF NOT EXISTS stage_table (
  25. stage_name VARCHAR NOT NULL REFERENCES stage_status,
  26. st_ns VARCHAR NOT NULL DEFAULT 'public',
  27. st_name VARCHAR NOT NULL
  28. );
  29. DO $cv$
  30. BEGIN
  31. CREATE VIEW stage_table_oids
  32. AS SELECT stage_name, st_ns, st_name, c.oid AS oid, c.relkind AS kind
  33. FROM stage_table
  34. LEFT OUTER JOIN pg_namespace ns ON (ns.nspname = st_ns)
  35. LEFT OUTER JOIN pg_class c ON (c.relnamespace = ns.oid AND c.relname = st_name);
  36. EXCEPTION
  37. WHEN duplicate_table THEN RETURN;
  38. END;
  39. $cv$;
  40. INSERT INTO stage_status (stage_name, started_at, finished_at, stage_key)
  41. VALUES ('init', NOW(), NOW(), uuid_generate_v4())
  42. ON CONFLICT (stage_name) DO NOTHING;
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...