@manablox/db 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'drizzle-kit';
2
+
3
+ export default defineConfig({
4
+ schema: './src/schema.ts',
5
+ out: './migrations',
6
+ dialect: 'postgresql',
7
+ dbCredentials: {
8
+ url: process.env.DATABASE_URL ?? 'postgres://manablox:manablox@localhost:5432/manablox',
9
+ },
10
+ casing: 'snake_case',
11
+ });
@@ -0,0 +1,268 @@
1
+ CREATE TABLE "accounts" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "user_id" uuid NOT NULL,
4
+ "account_id" text NOT NULL,
5
+ "provider_id" text NOT NULL,
6
+ "access_token" text,
7
+ "refresh_token" text,
8
+ "access_token_expires_at" timestamp with time zone,
9
+ "refresh_token_expires_at" timestamp with time zone,
10
+ "scope" text,
11
+ "id_token" text,
12
+ "password" text,
13
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
14
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
15
+ );
16
+ --> statement-breakpoint
17
+ CREATE TABLE "apikeys" (
18
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
19
+ "name" text,
20
+ "start" text,
21
+ "prefix" text,
22
+ "key" text NOT NULL,
23
+ "user_id" uuid NOT NULL,
24
+ "enabled" boolean DEFAULT true NOT NULL,
25
+ "expires_at" timestamp with time zone,
26
+ "last_request" timestamp with time zone,
27
+ "permissions" text,
28
+ "metadata" text,
29
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
30
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
31
+ );
32
+ --> statement-breakpoint
33
+ CREATE TABLE "asset_variants" (
34
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
35
+ "asset_id" uuid NOT NULL,
36
+ "preset" text NOT NULL,
37
+ "format" text NOT NULL,
38
+ "key" text NOT NULL,
39
+ "width" integer,
40
+ "height" integer,
41
+ "size" integer NOT NULL,
42
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
43
+ );
44
+ --> statement-breakpoint
45
+ CREATE TABLE "assets" (
46
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
47
+ "space_id" uuid NOT NULL,
48
+ "driver" text DEFAULT 'local' NOT NULL,
49
+ "key" text NOT NULL,
50
+ "filename" text NOT NULL,
51
+ "name" text NOT NULL,
52
+ "mime_type" text NOT NULL,
53
+ "size" integer NOT NULL,
54
+ "width" integer,
55
+ "height" integer,
56
+ "duration" integer,
57
+ "checksum" text,
58
+ "alt" text,
59
+ "title" text,
60
+ "meta" jsonb DEFAULT '{}'::jsonb NOT NULL,
61
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
62
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
63
+ "created_by" uuid
64
+ );
65
+ --> statement-breakpoint
66
+ CREATE TABLE "content_types" (
67
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
68
+ "space_id" uuid,
69
+ "name" text NOT NULL,
70
+ "label" text NOT NULL,
71
+ "description" text,
72
+ "icon" text,
73
+ "kind" text DEFAULT 'content' NOT NULL,
74
+ "has_slug" boolean DEFAULT true NOT NULL,
75
+ "is_publishable" boolean DEFAULT true NOT NULL,
76
+ "is_visible_in_tree" boolean DEFAULT true NOT NULL,
77
+ "can_be_visible_in_menu" boolean DEFAULT true NOT NULL,
78
+ "fields" jsonb DEFAULT '[]'::jsonb NOT NULL,
79
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
80
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
81
+ CONSTRAINT "content_types_space_name_key" UNIQUE NULLS NOT DISTINCT("space_id","name")
82
+ );
83
+ --> statement-breakpoint
84
+ CREATE TABLE "content_versions" (
85
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
86
+ "content_id" uuid NOT NULL,
87
+ "version" integer NOT NULL,
88
+ "label" text,
89
+ "snapshot" jsonb NOT NULL,
90
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
91
+ "created_by" uuid
92
+ );
93
+ --> statement-breakpoint
94
+ CREATE TABLE "contents" (
95
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
96
+ "space_id" uuid NOT NULL,
97
+ "type_id" uuid NOT NULL,
98
+ "locale" text NOT NULL,
99
+ "localization_id" uuid NOT NULL,
100
+ "parent_id" uuid,
101
+ "title" text NOT NULL,
102
+ "slug" text NOT NULL,
103
+ "path" "ltree" NOT NULL,
104
+ "permalink" text,
105
+ "permalink_segment" text,
106
+ "status" text DEFAULT 'draft' NOT NULL,
107
+ "visible_in_menu" boolean DEFAULT false NOT NULL,
108
+ "position" integer DEFAULT 0 NOT NULL,
109
+ "fields" jsonb DEFAULT '{}'::jsonb NOT NULL,
110
+ "search_text" text DEFAULT '' NOT NULL,
111
+ "version" integer DEFAULT 1 NOT NULL,
112
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
113
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
114
+ "created_by" uuid,
115
+ "updated_by" uuid,
116
+ "published_at" timestamp with time zone,
117
+ "search" "tsvector" GENERATED ALWAYS AS (to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(search_text, ''))) STORED,
118
+ CONSTRAINT "contents_sibling_slug_key" UNIQUE NULLS NOT DISTINCT("space_id","parent_id","locale","slug")
119
+ );
120
+ --> statement-breakpoint
121
+ CREATE TABLE "memberships" (
122
+ "user_id" uuid NOT NULL,
123
+ "space_id" uuid NOT NULL,
124
+ "role" text DEFAULT 'editor' NOT NULL,
125
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
126
+ CONSTRAINT "memberships_user_id_space_id_pk" PRIMARY KEY("user_id","space_id")
127
+ );
128
+ --> statement-breakpoint
129
+ CREATE TABLE "published_contents" (
130
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
131
+ "space_id" uuid NOT NULL,
132
+ "type_id" uuid NOT NULL,
133
+ "locale" text NOT NULL,
134
+ "localization_id" uuid NOT NULL,
135
+ "parent_id" uuid,
136
+ "title" text NOT NULL,
137
+ "slug" text NOT NULL,
138
+ "path" "ltree" NOT NULL,
139
+ "permalink" text,
140
+ "permalink_segment" text,
141
+ "status" text DEFAULT 'draft' NOT NULL,
142
+ "visible_in_menu" boolean DEFAULT false NOT NULL,
143
+ "position" integer DEFAULT 0 NOT NULL,
144
+ "fields" jsonb DEFAULT '{}'::jsonb NOT NULL,
145
+ "search_text" text DEFAULT '' NOT NULL,
146
+ "version" integer DEFAULT 1 NOT NULL,
147
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
148
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
149
+ "created_by" uuid,
150
+ "updated_by" uuid,
151
+ "published_at" timestamp with time zone,
152
+ "source_version" integer DEFAULT 1 NOT NULL,
153
+ "search" "tsvector" GENERATED ALWAYS AS (to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(search_text, ''))) STORED
154
+ );
155
+ --> statement-breakpoint
156
+ CREATE TABLE "sessions" (
157
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
158
+ "user_id" uuid NOT NULL,
159
+ "token" text NOT NULL,
160
+ "expires_at" timestamp with time zone NOT NULL,
161
+ "ip_address" text,
162
+ "user_agent" text,
163
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
164
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
165
+ );
166
+ --> statement-breakpoint
167
+ CREATE TABLE "spaces" (
168
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
169
+ "name" text NOT NULL,
170
+ "machine_name" text NOT NULL,
171
+ "description" text,
172
+ "url" text NOT NULL,
173
+ "default_locale" text DEFAULT 'en' NOT NULL,
174
+ "locales" jsonb DEFAULT '["en"]'::jsonb NOT NULL,
175
+ "settings" jsonb DEFAULT '{}'::jsonb NOT NULL,
176
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
177
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
178
+ );
179
+ --> statement-breakpoint
180
+ CREATE TABLE "users" (
181
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
182
+ "name" text DEFAULT '' NOT NULL,
183
+ "email" text NOT NULL,
184
+ "email_verified" boolean DEFAULT false NOT NULL,
185
+ "image" text,
186
+ "role" text DEFAULT 'editor' NOT NULL,
187
+ "banned" boolean DEFAULT false NOT NULL,
188
+ "ban_reason" text,
189
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
190
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
191
+ );
192
+ --> statement-breakpoint
193
+ CREATE TABLE "verifications" (
194
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
195
+ "identifier" text NOT NULL,
196
+ "value" text NOT NULL,
197
+ "expires_at" timestamp with time zone NOT NULL,
198
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
199
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
200
+ );
201
+ --> statement-breakpoint
202
+ CREATE TABLE "webhook_deliveries" (
203
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
204
+ "webhook_id" uuid NOT NULL,
205
+ "event" text NOT NULL,
206
+ "payload" jsonb NOT NULL,
207
+ "status" integer,
208
+ "error" text,
209
+ "attempt" integer DEFAULT 1 NOT NULL,
210
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
211
+ );
212
+ --> statement-breakpoint
213
+ CREATE TABLE "webhooks" (
214
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
215
+ "space_id" uuid NOT NULL,
216
+ "name" text NOT NULL,
217
+ "url" text NOT NULL,
218
+ "secret" text,
219
+ "events" jsonb DEFAULT '[]'::jsonb NOT NULL,
220
+ "enabled" boolean DEFAULT true NOT NULL,
221
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
222
+ );
223
+ --> statement-breakpoint
224
+ ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
225
+ ALTER TABLE "apikeys" ADD CONSTRAINT "apikeys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
226
+ ALTER TABLE "asset_variants" ADD CONSTRAINT "asset_variants_asset_id_assets_id_fk" FOREIGN KEY ("asset_id") REFERENCES "public"."assets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
227
+ ALTER TABLE "assets" ADD CONSTRAINT "assets_space_id_spaces_id_fk" FOREIGN KEY ("space_id") REFERENCES "public"."spaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
228
+ ALTER TABLE "content_types" ADD CONSTRAINT "content_types_space_id_spaces_id_fk" FOREIGN KEY ("space_id") REFERENCES "public"."spaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
229
+ ALTER TABLE "contents" ADD CONSTRAINT "contents_space_id_spaces_id_fk" FOREIGN KEY ("space_id") REFERENCES "public"."spaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
230
+ ALTER TABLE "memberships" ADD CONSTRAINT "memberships_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
231
+ ALTER TABLE "memberships" ADD CONSTRAINT "memberships_space_id_spaces_id_fk" FOREIGN KEY ("space_id") REFERENCES "public"."spaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
232
+ ALTER TABLE "published_contents" ADD CONSTRAINT "published_contents_space_id_spaces_id_fk" FOREIGN KEY ("space_id") REFERENCES "public"."spaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
233
+ ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
234
+ ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_webhook_id_webhooks_id_fk" FOREIGN KEY ("webhook_id") REFERENCES "public"."webhooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
235
+ ALTER TABLE "webhooks" ADD CONSTRAINT "webhooks_space_id_spaces_id_fk" FOREIGN KEY ("space_id") REFERENCES "public"."spaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
236
+ CREATE UNIQUE INDEX "accounts_provider_account_key" ON "accounts" USING btree ("provider_id","account_id");--> statement-breakpoint
237
+ CREATE INDEX "apikeys_user_idx" ON "apikeys" USING btree ("user_id");--> statement-breakpoint
238
+ CREATE UNIQUE INDEX "asset_variants_asset_preset_format_key" ON "asset_variants" USING btree ("asset_id","preset","format");--> statement-breakpoint
239
+ CREATE UNIQUE INDEX "assets_driver_key_key" ON "assets" USING btree ("driver","key");--> statement-breakpoint
240
+ CREATE INDEX "assets_space_idx" ON "assets" USING btree ("space_id","created_at");--> statement-breakpoint
241
+ CREATE INDEX "assets_checksum_idx" ON "assets" USING btree ("space_id","checksum");--> statement-breakpoint
242
+ CREATE INDEX "assets_mime_idx" ON "assets" USING btree ("space_id","mime_type");--> statement-breakpoint
243
+ CREATE INDEX "content_types_space_idx" ON "content_types" USING btree ("space_id");--> statement-breakpoint
244
+ CREATE UNIQUE INDEX "content_versions_content_version_key" ON "content_versions" USING btree ("content_id","version");--> statement-breakpoint
245
+ CREATE INDEX "content_versions_content_idx" ON "content_versions" USING btree ("content_id","created_at");--> statement-breakpoint
246
+ CREATE INDEX "contents_path_gist_idx" ON "contents" USING gist ("path");--> statement-breakpoint
247
+ CREATE INDEX "contents_parent_idx" ON "contents" USING btree ("parent_id");--> statement-breakpoint
248
+ CREATE INDEX "contents_space_type_idx" ON "contents" USING btree ("space_id","type_id");--> statement-breakpoint
249
+ CREATE INDEX "contents_localization_idx" ON "contents" USING btree ("localization_id");--> statement-breakpoint
250
+ CREATE INDEX "contents_status_idx" ON "contents" USING btree ("space_id","status");--> statement-breakpoint
251
+ CREATE INDEX "contents_fields_gin_idx" ON "contents" USING gin ("fields" jsonb_path_ops);--> statement-breakpoint
252
+ CREATE INDEX "contents_search_gin_idx" ON "contents" USING gin ("search");--> statement-breakpoint
253
+ CREATE UNIQUE INDEX "contents_permalink_key" ON "contents" USING btree ("space_id","locale","permalink") WHERE permalink is not null;--> statement-breakpoint
254
+ CREATE INDEX "memberships_space_idx" ON "memberships" USING btree ("space_id");--> statement-breakpoint
255
+ CREATE INDEX "published_contents_path_gist_idx" ON "published_contents" USING gist ("path");--> statement-breakpoint
256
+ CREATE INDEX "published_contents_parent_idx" ON "published_contents" USING btree ("parent_id");--> statement-breakpoint
257
+ CREATE INDEX "published_contents_space_type_idx" ON "published_contents" USING btree ("space_id","type_id");--> statement-breakpoint
258
+ CREATE INDEX "published_contents_fields_gin_idx" ON "published_contents" USING gin ("fields" jsonb_path_ops);--> statement-breakpoint
259
+ CREATE INDEX "published_contents_search_gin_idx" ON "published_contents" USING gin ("search");--> statement-breakpoint
260
+ CREATE UNIQUE INDEX "published_contents_permalink_key" ON "published_contents" USING btree ("space_id","locale","permalink") WHERE permalink is not null;--> statement-breakpoint
261
+ CREATE UNIQUE INDEX "sessions_token_key" ON "sessions" USING btree ("token");--> statement-breakpoint
262
+ CREATE INDEX "sessions_user_idx" ON "sessions" USING btree ("user_id");--> statement-breakpoint
263
+ CREATE INDEX "sessions_expires_idx" ON "sessions" USING btree ("expires_at");--> statement-breakpoint
264
+ CREATE UNIQUE INDEX "spaces_machine_name_key" ON "spaces" USING btree ("machine_name");--> statement-breakpoint
265
+ CREATE UNIQUE INDEX "users_email_key" ON "users" USING btree ("email");--> statement-breakpoint
266
+ CREATE INDEX "verifications_identifier_idx" ON "verifications" USING btree ("identifier");--> statement-breakpoint
267
+ CREATE INDEX "webhook_deliveries_webhook_idx" ON "webhook_deliveries" USING btree ("webhook_id","created_at");--> statement-breakpoint
268
+ CREATE INDEX "webhooks_space_idx" ON "webhooks" USING btree ("space_id");
@@ -0,0 +1,2 @@
1
+ ALTER TABLE "contents" ADD COLUMN "permalink_path" text DEFAULT '' NOT NULL;--> statement-breakpoint
2
+ ALTER TABLE "published_contents" ADD COLUMN "permalink_path" text DEFAULT '' NOT NULL;
@@ -0,0 +1 @@
1
+ ALTER TABLE "accounts" ADD COLUMN "issuer" text DEFAULT '' NOT NULL;
@@ -0,0 +1,14 @@
1
+ CREATE TABLE "asset_usages" (
2
+ "asset_id" uuid NOT NULL,
3
+ "content_id" uuid NOT NULL,
4
+ "space_id" uuid NOT NULL,
5
+ "published" boolean DEFAULT false NOT NULL,
6
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
7
+ CONSTRAINT "asset_usages_asset_id_content_id_pk" PRIMARY KEY("asset_id","content_id")
8
+ );
9
+ --> statement-breakpoint
10
+ ALTER TABLE "asset_usages" ADD CONSTRAINT "asset_usages_asset_id_assets_id_fk" FOREIGN KEY ("asset_id") REFERENCES "public"."assets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
11
+ ALTER TABLE "asset_usages" ADD CONSTRAINT "asset_usages_content_id_contents_id_fk" FOREIGN KEY ("content_id") REFERENCES "public"."contents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
12
+ ALTER TABLE "asset_usages" ADD CONSTRAINT "asset_usages_space_id_spaces_id_fk" FOREIGN KEY ("space_id") REFERENCES "public"."spaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
13
+ CREATE INDEX "asset_usages_published_idx" ON "asset_usages" USING btree ("asset_id","published");--> statement-breakpoint
14
+ CREATE INDEX "asset_usages_content_idx" ON "asset_usages" USING btree ("content_id");
@@ -0,0 +1 @@
1
+ ALTER TABLE "apikeys" ADD COLUMN "space_ids" jsonb;