H-290: enforce Captain Skill tenant bindings (#51)
* H-290: enforce Captain Skill tenant consistency * H-290: fix SQLite tenant migration coverage * H-290: leave tenant constraints to migrations --------- Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
ALTER TABLE captain_assistant_skills
|
||||
DROP CONSTRAINT IF EXISTS fk_captain_assistant_skills_assistant_tenant,
|
||||
DROP CONSTRAINT IF EXISTS fk_captain_assistant_skills_skill_tenant;
|
||||
|
||||
DROP INDEX IF EXISTS idx_captain_assistants_account_id_id;
|
||||
DROP INDEX IF EXISTS idx_captain_skills_account_id_id;
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE UNIQUE INDEX idx_captain_assistants_account_id_id
|
||||
ON captain_assistants(account_id, id);
|
||||
CREATE UNIQUE INDEX idx_captain_skills_account_id_id
|
||||
ON captain_skills(account_id, id);
|
||||
|
||||
ALTER TABLE captain_assistant_skills
|
||||
ADD CONSTRAINT fk_captain_assistant_skills_assistant_tenant
|
||||
FOREIGN KEY (account_id, assistant_id)
|
||||
REFERENCES captain_assistants(account_id, id) ON DELETE CASCADE,
|
||||
ADD CONSTRAINT fk_captain_assistant_skills_skill_tenant
|
||||
FOREIGN KEY (account_id, skill_id)
|
||||
REFERENCES captain_skills(account_id, id) ON DELETE CASCADE;
|
||||
@@ -0,0 +1,21 @@
|
||||
CREATE TABLE captain_assistant_skills_000081 (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
account_id INTEGER NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
|
||||
assistant_id INTEGER NOT NULL REFERENCES captain_assistants(id) ON DELETE CASCADE,
|
||||
skill_id INTEGER NOT NULL REFERENCES captain_skills(id) ON DELETE CASCADE,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE (assistant_id, skill_id)
|
||||
);
|
||||
|
||||
INSERT INTO captain_assistant_skills_000081
|
||||
(id, account_id, assistant_id, skill_id, created_at)
|
||||
SELECT id, account_id, assistant_id, skill_id, created_at
|
||||
FROM captain_assistant_skills;
|
||||
|
||||
DROP TABLE captain_assistant_skills;
|
||||
ALTER TABLE captain_assistant_skills_000081 RENAME TO captain_assistant_skills;
|
||||
CREATE INDEX idx_captain_assistant_skills_account ON captain_assistant_skills(account_id);
|
||||
CREATE INDEX idx_captain_assistant_skills_skill ON captain_assistant_skills(skill_id);
|
||||
|
||||
DROP INDEX idx_captain_assistants_account_id_id;
|
||||
DROP INDEX idx_captain_skills_account_id_id;
|
||||
@@ -0,0 +1,29 @@
|
||||
CREATE UNIQUE INDEX idx_captain_assistants_account_id_id
|
||||
ON captain_assistants(account_id, id);
|
||||
CREATE UNIQUE INDEX idx_captain_skills_account_id_id
|
||||
ON captain_skills(account_id, id);
|
||||
|
||||
CREATE TABLE captain_assistant_skills_000081 (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
account_id INTEGER NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
|
||||
assistant_id INTEGER NOT NULL,
|
||||
skill_id INTEGER NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE (assistant_id, skill_id),
|
||||
CONSTRAINT fk_captain_assistant_skills_assistant_tenant
|
||||
FOREIGN KEY (account_id, assistant_id)
|
||||
REFERENCES captain_assistants(account_id, id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_captain_assistant_skills_skill_tenant
|
||||
FOREIGN KEY (account_id, skill_id)
|
||||
REFERENCES captain_skills(account_id, id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
INSERT INTO captain_assistant_skills_000081
|
||||
(id, account_id, assistant_id, skill_id, created_at)
|
||||
SELECT id, account_id, assistant_id, skill_id, created_at
|
||||
FROM captain_assistant_skills;
|
||||
|
||||
DROP TABLE captain_assistant_skills;
|
||||
ALTER TABLE captain_assistant_skills_000081 RENAME TO captain_assistant_skills;
|
||||
CREATE INDEX idx_captain_assistant_skills_account ON captain_assistant_skills(account_id);
|
||||
CREATE INDEX idx_captain_assistant_skills_skill ON captain_assistant_skills(skill_id);
|
||||
Reference in New Issue
Block a user