emissary/migrations/sqlite/0000005_spec_version.up.sql

36 lines
763 B
SQL

-- 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;