MCPcopy Create free account
hub / github.com/crossjoin-io/crossjoin / setupDatabase

Function setupDatabase

api/db.go:9–108  ·  view source on GitHub ↗

setupDatabase sets up the database and schema migrations.

(db *sql.DB)

Source from the content-addressed store, hash-verified

7
8// setupDatabase sets up the database and schema migrations.
9func setupDatabase(db *sql.DB) error {
10 migrations := []string{
11 /* 000 */ `CREATE TABLE IF NOT EXISTS schema_version (version INT PRIMARY KEY, timestamp TIMESTAMP)`,
12 /* 001 */ `
13 CREATE TABLE IF NOT EXISTS configs (
14 loaded_at TIMESTAMP NOT NULL,
15 hash TEXT NOT NULL,
16 config JSON NOT NULL
17 );
18 CREATE TABLE IF NOT EXISTS workflows (
19 config_hash TEXT NOT NULL,
20 id TEXT NOT NULL,
21 text TEXT NOT NULL,
22 PRIMARY KEY (config_hash, id)
23 );
24 CREATE TABLE IF NOT EXISTS workflow_runs (
25 id TEXT NOT NULL PRIMARY KEY,
26 config_hash TEXT NOT NULL,
27 workflow_id TEXT NOT NULL,
28 started_at TIMESTAMP,
29 completed_at TIMESTAMP,
30 success BOOL
31 );
32 CREATE TABLE tasks (
33 id TEXT NOT NULL PRIMARY KEY,
34 workflow_run_id TEXT NOT NULL,
35 workflow_task_id TEXT NOT NULL,
36 input JSON NOT NULL DEFAULT '{}',
37 output JSON NOT NULL DEFAULT '{}',
38 created_at TIMESTAMP NOT NULL,
39 started_at TIMESTAMP,
40 timeout_at TIMESTAMP,
41 completed_at TIMESTAMP,
42 attempts_left NOT NULL DEFAULT 3,
43 stdout TEXT,
44 stderr TEXT,
45 success BOOL
46 );
47 CREATE TABLE IF NOT EXISTS data_connections (
48 config_hash TEXT NOT NULL,
49 id TEXT NOT NULL,
50 type TEXT NOT NULL,
51 path TEXT,
52 connection_string TEXT,
53 PRIMARY KEY (config_hash, id)
54 );
55 CREATE TABLE IF NOT EXISTS datasets (
56 config_hash TEXT NOT NULL,
57 id TEXT NOT NULL,
58 text TEXT NOT NULL,
59 PRIMARY KEY (config_hash, id)
60 )
61 `,
62 }
63
64 tx, err := db.Begin()
65 if err != nil {
66 return err

Callers 1

NewAPIFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected