feat: add spec definition api with versioning
This commit is contained in:
1
migrations/sqlite/0000004_spec_definition.down.sql
Normal file
1
migrations/sqlite/0000004_spec_definition.down.sql
Normal file
@ -0,0 +1 @@
|
||||
DROP TABLE spec_definitions;
|
9
migrations/sqlite/0000004_spec_definition.up.sql
Normal file
9
migrations/sqlite/0000004_spec_definition.up.sql
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE
|
||||
spec_definitions (
|
||||
name TEXT NOT NULL,
|
||||
version TEXT NOT NULL,
|
||||
schema TEXT NOT NULL,
|
||||
created_at datetime NOT NULL,
|
||||
updated_at datetime NOT NULL,
|
||||
UNIQUE (name, version)
|
||||
);
|
35
migrations/sqlite/0000005_spec_version.down.sql
Normal file
35
migrations/sqlite/0000005_spec_version.down.sql
Normal file
@ -0,0 +1,35 @@
|
||||
ALTER TABLE specs
|
||||
RENAME TO _specs;
|
||||
|
||||
CREATE TABLE
|
||||
specs (
|
||||
id INTEGER PRIMARY KEY,
|
||||
agent_id INTEGER,
|
||||
tenant_id TEXT,
|
||||
name TEXT NOT NULL,
|
||||
revision INTEGER DEFAULT 0,
|
||||
data TEXT,
|
||||
created_at datetime NOT NULL,
|
||||
updated_at datetime NOT NULL,
|
||||
FOREIGN KEY (tenant_id) REFERENCES tenants (id),
|
||||
FOREIGN KEY (agent_id) REFERENCES agents (id) ON DELETE CASCADE,
|
||||
UNIQUE (agent_id, name) ON CONFLICT REPLACE
|
||||
);
|
||||
|
||||
INSERT INTO
|
||||
specs
|
||||
SELECT
|
||||
id,
|
||||
agent_id,
|
||||
tenant_id,
|
||||
name,
|
||||
revision,
|
||||
data,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
_specs;
|
||||
|
||||
DROP TABLE _specs;
|
||||
|
||||
---
|
36
migrations/sqlite/0000005_spec_version.up.sql
Normal file
36
migrations/sqlite/0000005_spec_version.up.sql
Normal file
@ -0,0 +1,36 @@
|
||||
-- Add unique constraint on name/version to specs
|
||||
ALTER TABLE specs
|
||||
RENAME TO _specs;
|
||||
|
||||
CREATE TABLE
|
||||
specs (
|
||||
id INTEGER PRIMARY KEY,
|
||||
agent_id INTEGER,
|
||||
tenant_id TEXT,
|
||||
name TEXT NOT NULL,
|
||||
version TEXT NOT NULL,
|
||||
revision INTEGER DEFAULT 0,
|
||||
data TEXT,
|
||||
created_at datetime NOT NULL,
|
||||
updated_at datetime NOT NULL,
|
||||
FOREIGN KEY (tenant_id) REFERENCES tenants (id),
|
||||
FOREIGN KEY (agent_id) REFERENCES agents (id) ON DELETE CASCADE,
|
||||
UNIQUE (agent_id, name, version) ON CONFLICT REPLACE
|
||||
);
|
||||
|
||||
INSERT INTO
|
||||
specs
|
||||
SELECT
|
||||
id,
|
||||
agent_id,
|
||||
tenant_id,
|
||||
name,
|
||||
"0.0.0",
|
||||
revision,
|
||||
data,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
_specs;
|
||||
|
||||
DROP TABLE _specs;
|
Reference in New Issue
Block a user