CREATE TABLE "domains" ( "id" varchar(255) PRIMARY KEY, "friendly_name" varchar(255), "support_email" varchar(255), "created_at" datetime, "updated_at" datetime ); CREATE TABLE "tenants" ( "id" int PRIMARY KEY, "name" varchar(255), "domain_id" varchar(255), "created_at" datetime, "updated_at" datetime, FOREIGN KEY("domain_id") REFERENCES "domains" ("id") ); CREATE TABLE "resource_types" ( "id" int PRIMARY KEY, "name" varchar(255), "domain_id" varchar(255), "created_at" datetime, "updated_at" datetime, FOREIGN KEY("domain_id") REFERENCES "domains" ("id") ); CREATE TABLE "role_templates" ( "id" int PRIMARY KEY, "name" varchar(255), "domain_id" varchar(255), "created_at" datetime, "updated_at" datetime, FOREIGN KEY("domain_id") REFERENCES "domains" ("id") ); CREATE TABLE "actions" ( "id" int PRIMARY KEY, "name" varchar(255), "resource_type_id" int, "created_at" datetime, "updated_at" datetime, FOREIGN KEY("resource_type_id") REFERENCES "resource_types" ("id") ); CREATE TABLE "role_template_permissions" ( "id" int PRIMARY KEY, "resource_path" varchar(255), "action_id" int, "allow_deny" varchar(255), "role_template_id" int, "created_at" datetime, "updated_at" datetime, FOREIGN KEY("action_id") REFERENCES "actions" ("id"), FOREIGN KEY("role_template_id") REFERENCES "role_templates" ("id") ); CREATE TABLE "roles" ( "id" int PRIMARY KEY, "name" varchar(255), "tenant_id" int, "inherits_role_id" int, "role_template_id" int, "created_at" datetime, "updated_at" datetime, FOREIGN KEY("tenant_id") REFERENCES "tenants" ("id"), FOREIGN KEY("inherits_role_id") REFERENCES "roles" ("id"), FOREIGN KEY("role_template_id") REFERENCES "role_templates" ("id") ); CREATE TABLE "role_permissions" ( "id" int PRIMARY KEY, "resource_path" varchar(255), "action_id" int, "allow_deny" varchar(255), "role_id" int, "created_at" datetime, "updated_at" datetime, FOREIGN KEY("action_id") REFERENCES "actions" ("id"), FOREIGN KEY("role_id") REFERENCES "roles" ("id") ); CREATE TABLE "role_trust" ( "id" int PRIMARY KEY, "usertype" varchar(255), "identifier" varchar(255), "role_id" int, "created_at" datetime, "updated_at" datetime, FOREIGN KEY("role_id") REFERENCES "roles" ("id") );