-- termix-identity 0001: adopt_termix_identity_tables -- Generated by termix-plugin migrations. Review before committing. -- Hand-edited: keeps the legacy foreign keys the SDK cannot declare -- (keys and ca to their identity, keys to ssh_credentials). CREATE TABLE IF NOT EXISTS "termix_identities" ( "id" integer PRIMARY KEY AUTOINCREMENT, "user_id" text NOT NULL UNIQUE, "handle" text NOT NULL UNIQUE, "description" text, "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ); ALTER TABLE "termix_identities" RENAME TO "p_termix_identity_identities"; CREATE TABLE IF NOT EXISTS "termix_identity_keys" ( "id" integer PRIMARY KEY AUTOINCREMENT, "identity_id" integer NOT NULL, "user_id" text NOT NULL, "public_key" text NOT NULL, "key_type" text NOT NULL, "algorithm" text NOT NULL, "label" text, "comment" text, "source" text NOT NULL DEFAULT 'manual', "credential_id" integer, "enabled" integer NOT NULL DEFAULT 1, "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE, FOREIGN KEY ("identity_id") REFERENCES "p_termix_identity_identities" ("id") ON DELETE CASCADE, FOREIGN KEY ("credential_id") REFERENCES "ssh_credentials" ("id") ON DELETE SET NULL ); CREATE INDEX IF NOT EXISTS "idx_termix_identity_keys_identity" ON "termix_identity_keys" ("identity_id"); ALTER TABLE "termix_identity_keys" RENAME TO "p_termix_identity_keys"; CREATE TABLE IF NOT EXISTS "termix_identity_ca" ( "id" integer PRIMARY KEY AUTOINCREMENT, "identity_id" integer NOT NULL UNIQUE, "user_id" text NOT NULL, "public_key" text NOT NULL, "private_key" text NOT NULL, "validity_days" integer NOT NULL DEFAULT 90, "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE, FOREIGN KEY ("identity_id") REFERENCES "p_termix_identity_identities" ("id") ON DELETE CASCADE ); ALTER TABLE "termix_identity_ca" RENAME TO "p_termix_identity_ca";