40 lines
815 B
SQL
40 lines
815 B
SQL
-- Add unique constraint on name/version to specs
|
|
PRAGMA foreign_keys = 0;
|
|
|
|
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;
|
|
|
|
PRAGMA foreign_keys = 1; |