This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
-- SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
||||
create table `outbox` (
|
||||
`id` char(36) primary key,
|
||||
`org_id` char(36) not null,
|
||||
`name` text not null,
|
||||
`payload` json not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`attempts` integer not null,
|
||||
`published_at` datetime(6),
|
||||
`last_error` text,
|
||||
`deferrals` integer not null default 0,
|
||||
`deferred_since` datetime(6),
|
||||
`deferred_until` datetime(6)
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
create index `outbox_pending_idx` on `outbox` (`created_at`);
|
||||
|
||||
create table `idempotency_keys` (
|
||||
`org_id` char(36) not null,
|
||||
-- Not null, with the zero uuid where a scope has no workspace or project: a primary key
|
||||
-- ignores a row whose column is NULL, and the key would stop being unique.
|
||||
`workspace_id` char(36) not null,
|
||||
`project_id` char(36) not null,
|
||||
`procedure` varchar(255) not null,
|
||||
`key` varchar(255) not null,
|
||||
-- The response may itself be the JSON value null, so "finished" is a column of its own
|
||||
-- rather than a non-null response. Null while the transaction that claimed this key is
|
||||
-- running; a second caller's insert blocks on the key until that transaction ends.
|
||||
`response` json,
|
||||
`completed_at` datetime(6),
|
||||
`created_at` datetime(6) not null,
|
||||
primary key (`org_id`, `workspace_id`, `project_id`, `procedure`, `key`)
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
create table `auth_api_keys` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`org_id` char(36) not null,
|
||||
`name` text not null,
|
||||
`token_hash` text not null,
|
||||
`prefix` text not null,
|
||||
`user_id` char(36) not null,
|
||||
`expires_at` text,
|
||||
`revoked_at` text
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `auth_api_keys` add constraint `auth_api_keys_org_id_token_hash_key` unique (`org_id`, `token_hash`);
|
||||
|
||||
create index `auth_api_keys_org_id_user_id_idx` on `auth_api_keys` (`org_id`, `user_id`);
|
||||
|
||||
create index `auth_api_keys_org_id_prefix_idx` on `auth_api_keys` (`org_id`, `prefix`(191));
|
||||
|
||||
create table `auth_sessions` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`user_id` char(36) not null,
|
||||
`issuer` text not null,
|
||||
`subject` text not null,
|
||||
`handle_hash` text not null,
|
||||
`tokens` text not null,
|
||||
`access_token_expires_at` text not null,
|
||||
`last_seen_at` text not null,
|
||||
`absolute_expires_at` text not null,
|
||||
`revoked_at` text
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `auth_sessions` add constraint `auth_sessions_handle_hash_key` unique (`handle_hash`);
|
||||
|
||||
create index `auth_sessions_user_id_idx` on `auth_sessions` (`user_id`);
|
||||
|
||||
create index `auth_sessions_absolute_expires_at_idx` on `auth_sessions` (`absolute_expires_at`(191));
|
||||
|
||||
create table `extensions` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`org_id` char(36) not null,
|
||||
`subject_type` text not null,
|
||||
`subject_id` char(36) not null,
|
||||
`namespace` text not null,
|
||||
`payload` json not null,
|
||||
`payload_version` integer not null
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `extensions` add constraint `extensions_org_id_subject_type_subject_id_namespace_key` unique (`org_id`, `subject_type`, `subject_id`, `namespace`);
|
||||
|
||||
create index `extensions_org_id_namespace_idx` on `extensions` (`org_id`, `namespace`(191));
|
||||
|
||||
create table `invitations` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`org_id` char(36) not null,
|
||||
`email` text not null,
|
||||
`role` text not null,
|
||||
`workspace_id` char(36),
|
||||
`workspace_role` text,
|
||||
`token_hash` text not null,
|
||||
`expires_at` text not null,
|
||||
`accepted_at` text,
|
||||
`invited_by` char(36) not null
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `invitations` add constraint `invitations_org_id_token_hash_key` unique (`org_id`, `token_hash`);
|
||||
|
||||
create index `invitations_org_id_email_idx` on `invitations` (`org_id`, `email`(191));
|
||||
|
||||
create index `invitations_org_id_accepted_at_idx` on `invitations` (`org_id`, `accepted_at`(191));
|
||||
|
||||
create table `org_memberships` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`org_id` char(36) not null,
|
||||
`user_id` char(36) not null,
|
||||
`role` text not null
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `org_memberships` add constraint `org_memberships_org_id_user_id_key` unique (`org_id`, `user_id`);
|
||||
|
||||
create index `org_memberships_org_id_role_idx` on `org_memberships` (`org_id`, `role`(191));
|
||||
|
||||
create table `organizations` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`slug` text not null,
|
||||
`name` text not null,
|
||||
`status` text not null,
|
||||
`settings` json not null,
|
||||
`branding` json
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `organizations` add constraint `organizations_slug_key` unique (`slug`);
|
||||
|
||||
create index `organizations_status_idx` on `organizations` (`status`(191));
|
||||
|
||||
create table `projects` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`org_id` char(36) not null,
|
||||
`workspace_id` char(36) not null,
|
||||
`slug` text not null,
|
||||
`name` text not null,
|
||||
`module_key` text not null,
|
||||
`archived_at` text
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `projects` add constraint `projects_org_id_workspace_id_slug_key` unique (`org_id`, `workspace_id`, `slug`);
|
||||
|
||||
create index `projects_org_id_workspace_id_archived_at_idx` on `projects` (`org_id`, `workspace_id`, `archived_at`(191));
|
||||
|
||||
create table `users` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`issuer` text not null,
|
||||
`subject` text not null,
|
||||
`email` text not null,
|
||||
`display_name` text not null,
|
||||
`locale` text not null
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `users` add constraint `users_issuer_subject_key` unique (`issuer`, `subject`);
|
||||
|
||||
create index `users_email_idx` on `users` (`email`(191));
|
||||
|
||||
create table `workspace_memberships` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`org_id` char(36) not null,
|
||||
`workspace_id` char(36) not null,
|
||||
`user_id` char(36) not null,
|
||||
`role` text not null
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `workspace_memberships` add constraint `workspace_memberships_org_id_workspace_id_user_id_key` unique (`org_id`, `workspace_id`, `user_id`);
|
||||
|
||||
create index `workspace_memberships_org_id_user_id_idx` on `workspace_memberships` (`org_id`, `user_id`);
|
||||
|
||||
create table `workspaces` (
|
||||
`id` char(36) primary key,
|
||||
`version` integer not null,
|
||||
`created_at` datetime(6) not null,
|
||||
`updated_at` datetime(6) not null,
|
||||
`org_id` char(36) not null,
|
||||
`slug` text not null,
|
||||
`name` text not null,
|
||||
`is_default` boolean not null,
|
||||
`visibility` text not null
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
alter table `workspaces` add constraint `workspaces_org_id_slug_key` unique (`org_id`, `slug`);
|
||||
Reference in New Issue
Block a user