@s-hirano-ist/s-database 1.20.0 → 1.21.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.
- package/package.json +3 -4
- package/prisma/migrations/0_init/migration.sql +107 -0
- package/prisma/migrations/1_better_auth/migration.sql +69 -0
- package/prisma/migrations/migration_lock.toml +1 -1
- package/prisma/remap-userids-better-auth.sql +98 -0
- package/prisma/schema.prisma +112 -31
- package/src/generated/edge.js +56 -8
- package/src/generated/index-browser.js +51 -3
- package/src/generated/index.d.ts +6191 -35
- package/src/generated/index.js +56 -8
- package/src/generated/package.json +1 -1
- package/src/generated/query_compiler_fast_bg.wasm +0 -0
- package/src/generated/query_compiler_fast_bg.wasm-base64.js +1 -1
- package/src/generated/schema.prisma +112 -31
- package/src/index.ts +63 -7
- package/prisma/migrations/20241005070905_initial_with_user/migration.sql +0 -105
- package/prisma/migrations/20241005122052_category_unique_name/migration.sql +0 -11
- package/prisma/migrations/20241006114119_add_role/migration.sql +0 -5
- package/prisma/migrations/20241011230910_add_scope_and_username/migration.sql +0 -24
- package/prisma/migrations/20241012012914_migrate_user_verified_to_role/migration.sql +0 -11
- package/prisma/migrations/20241012014828_delete_user_email/migration.sql +0 -11
- package/prisma/migrations/20241013122009_delete_unique_on_profile_name/migration.sql +0 -2
- package/prisma/migrations/20241113115839_add_image_table/migration.sql +0 -13
- package/prisma/migrations/20241116050545_login_lock/migration.sql +0 -3
- package/prisma/migrations/20250104003943_delete_user_scope_column/migration.sql +0 -11
- package/prisma/migrations/20250104031930_delete_unauthorized_role_enum/migration.sql +0 -16
- package/prisma/migrations/20250104033736_change_user_role_enum_name/migration.sql +0 -19
- package/prisma/migrations/20250104064405_add_static_books_and_contents/migration.sql +0 -27
- package/prisma/migrations/20250113084254_drop_user_table/migration.sql +0 -37
- package/prisma/migrations/20250118084244_add_image_metadata/migration.sql +0 -14
- package/prisma/migrations/20250129231002_add_static_image_table/migration.sql +0 -14
- package/prisma/migrations/20250504020635_add_static_news_table/migration.sql +0 -27
- package/prisma/migrations/20250510025039_fix_no_unique_for_categories/migration.sql +0 -2
- package/prisma/migrations/20250614000736_add_google_api_data/migration.sql +0 -31
- package/prisma/migrations/20250719061839_add_og_for_static_news/migration.sql +0 -4
- package/prisma/migrations/20250730114244_delete_uint8arrayimage_from_static_books/migration.sql +0 -8
- package/prisma/migrations/20250811111733_delete_static_news/migration.sql +0 -20
- package/prisma/migrations/20250811115459_delete_updated_recently/migration.sql +0 -34
- package/prisma/migrations/20250811131348_merge_viewer_to_dumper/migration.sql +0 -54
- package/prisma/migrations/20250812234654_add_unique_costraints_on_unique_key/migration.sql +0 -19
- package/prisma/migrations/20250813033448_add_unique_constraints_on_images/migration.sql +0 -8
- package/prisma/migrations/20250813085846_delete_single_unique_constraints/migration.sql +0 -5
- package/prisma/migrations/20250813140904_change_id_from_int_to_uuid/migration.sql +0 -27
- package/prisma/migrations/20250813141347_move_image_id_to_paths/migration.sql +0 -15
- package/prisma/migrations/20250815002544_change_default_values/migration.sql +0 -39
- package/prisma/migrations/20250815040824_rename_images_paths_to_path/migration.sql +0 -17
- package/prisma/migrations/20250818232331_change_news_contents_to_article_note/migration.sql +0 -57
- package/prisma/migrations/20250819024722_delete_default_now_for_created_at/migration.sql +0 -14
- package/prisma/migrations/20251214044139_add_last_updated_to_status_schema/migration.sql +0 -2
- package/prisma/migrations/20260104035357_add_image_paths_for_book_dumper/migration.sql +0 -2
- package/prisma/migrations/20260118120015_add_schema_restrictions_on_cols/migration.sql +0 -93
- package/prisma/migrations/20260125055037_remove_image_tags_description/migration.sql +0 -10
- package/prisma/migrations/20260214022211_add_more_url_length_to_og_image/migration.sql +0 -2
- package/prisma/migrations/20260418090234_rating_to_required/migration.sql +0 -8
- package/prisma/migrations/20260419000000_merge_google_title_into_title/migration.sql +0 -15
- package/src/resolve-db-env.ts +0 -36
|
@@ -10,7 +10,7 @@ generator erd {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
datasource db {
|
|
13
|
-
provider = "
|
|
13
|
+
provider = "cockroachdb"
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
enum Status {
|
|
@@ -20,38 +20,38 @@ enum Status {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
model Category {
|
|
23
|
-
id String @id @db.
|
|
23
|
+
id String @id @db.String(36)
|
|
24
24
|
|
|
25
|
-
name String @db.
|
|
25
|
+
name String @db.String(16)
|
|
26
26
|
|
|
27
27
|
Articles Article[]
|
|
28
28
|
|
|
29
29
|
createdAt DateTime @map("created_at")
|
|
30
30
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
31
31
|
|
|
32
|
-
userId String @map("user_id") @db.
|
|
32
|
+
userId String @map("user_id") @db.String(128)
|
|
33
33
|
|
|
34
34
|
@@unique([name, userId])
|
|
35
35
|
@@map("categories")
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
model Article {
|
|
39
|
-
id String @id @db.
|
|
39
|
+
id String @id @db.String(36)
|
|
40
40
|
|
|
41
|
-
title String @db.
|
|
42
|
-
url String @db.
|
|
43
|
-
quote String? @db.
|
|
41
|
+
title String @db.String(128)
|
|
42
|
+
url String @db.String(2048)
|
|
43
|
+
quote String? @db.String(512)
|
|
44
44
|
|
|
45
|
-
ogImageUrl String? @map("og_image_url") @db.
|
|
46
|
-
ogTitle String? @map("og_title") @db.
|
|
47
|
-
ogDescription String? @map("og_description") @db.
|
|
45
|
+
ogImageUrl String? @map("og_image_url") @db.String(4096)
|
|
46
|
+
ogTitle String? @map("og_title") @db.String(512)
|
|
47
|
+
ogDescription String? @map("og_description") @db.String(1024)
|
|
48
48
|
|
|
49
49
|
Category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade, onUpdate: Cascade)
|
|
50
|
-
categoryId String @map("category_id") @db.
|
|
50
|
+
categoryId String @map("category_id") @db.String(36)
|
|
51
51
|
|
|
52
52
|
status Status
|
|
53
53
|
|
|
54
|
-
userId String @map("user_id") @db.
|
|
54
|
+
userId String @map("user_id") @db.String(128)
|
|
55
55
|
|
|
56
56
|
createdAt DateTime @map("created_at")
|
|
57
57
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
@@ -62,14 +62,14 @@ model Article {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
model Note {
|
|
65
|
-
id String @id @db.
|
|
65
|
+
id String @id @db.String(36)
|
|
66
66
|
|
|
67
|
-
title String @db.
|
|
68
|
-
markdown String @db.
|
|
67
|
+
title String @db.String(64)
|
|
68
|
+
markdown String @db.String
|
|
69
69
|
|
|
70
70
|
status Status
|
|
71
71
|
|
|
72
|
-
userId String @map("user_id") @db.
|
|
72
|
+
userId String @map("user_id") @db.String(128)
|
|
73
73
|
|
|
74
74
|
createdAt DateTime @map("created_at")
|
|
75
75
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
@@ -80,17 +80,17 @@ model Note {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
model Image {
|
|
83
|
-
id String @id @db.
|
|
83
|
+
id String @id @db.String(36)
|
|
84
84
|
|
|
85
|
-
path String @db.
|
|
86
|
-
contentType String @map("content_type") @db.
|
|
85
|
+
path String @db.String(512)
|
|
86
|
+
contentType String @map("content_type") @db.String(32) // e.g.: image/jpeg, image/png
|
|
87
87
|
fileSize Int? @map("file_size") // byte
|
|
88
88
|
width Int? // pixel
|
|
89
89
|
height Int? // pixel
|
|
90
90
|
|
|
91
91
|
status Status
|
|
92
92
|
|
|
93
|
-
userId String @map("user_id") @db.
|
|
93
|
+
userId String @map("user_id") @db.String(128)
|
|
94
94
|
|
|
95
95
|
createdAt DateTime @map("created_at")
|
|
96
96
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
@@ -101,26 +101,26 @@ model Image {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
model Book {
|
|
104
|
-
id String @id @db.
|
|
105
|
-
isbn String @db.
|
|
106
|
-
title String @db.
|
|
104
|
+
id String @id @db.String(36)
|
|
105
|
+
isbn String @db.String(17)
|
|
106
|
+
title String @db.String(512)
|
|
107
107
|
|
|
108
|
-
googleSubTitle String? @map("google_subtitle") @db.
|
|
108
|
+
googleSubTitle String? @map("google_subtitle") @db.String(512)
|
|
109
109
|
googleAuthors String[] @map("google_authors")
|
|
110
|
-
googleDescription String? @map("google_description") @db.
|
|
111
|
-
googleImgSrc String? @map("google_img_src") @db.
|
|
112
|
-
googleHref String? @map("google_href") @db.
|
|
110
|
+
googleDescription String? @map("google_description") @db.String
|
|
111
|
+
googleImgSrc String? @map("google_img_src") @db.String(2048)
|
|
112
|
+
googleHref String? @map("google_href") @db.String(2048)
|
|
113
113
|
|
|
114
|
-
imagePath String? @map("image_path") @db.
|
|
114
|
+
imagePath String? @map("image_path") @db.String(512)
|
|
115
115
|
|
|
116
|
-
markdown String? @db.
|
|
116
|
+
markdown String? @db.String
|
|
117
117
|
|
|
118
118
|
rating Int // 1-5
|
|
119
119
|
tags String[]
|
|
120
120
|
|
|
121
121
|
status Status
|
|
122
122
|
|
|
123
|
-
userId String @map("user_id") @db.
|
|
123
|
+
userId String @map("user_id") @db.String(128)
|
|
124
124
|
|
|
125
125
|
createdAt DateTime @map("created_at")
|
|
126
126
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
@@ -129,3 +129,84 @@ model Book {
|
|
|
129
129
|
@@unique([isbn, userId])
|
|
130
130
|
@@map("books")
|
|
131
131
|
}
|
|
132
|
+
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// Better Auth tables (user / session / account / verification).
|
|
135
|
+
//
|
|
136
|
+
// Managed entirely by Better Auth via @better-auth/prisma-adapter. These are
|
|
137
|
+
// intentionally NOT registered in the Prisma tenant extension whitelist
|
|
138
|
+
// (app/src/prisma.ts), so tenant filtering never touches them. createdAt has a
|
|
139
|
+
// DB default and emailVerified defaults to false as a safety net for the
|
|
140
|
+
// library-managed write paths (unlike the domain models, which set timestamps
|
|
141
|
+
// explicitly in domain logic).
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
model User {
|
|
145
|
+
id String @id @db.String(64)
|
|
146
|
+
|
|
147
|
+
name String @db.String
|
|
148
|
+
email String @unique @db.String
|
|
149
|
+
emailVerified Boolean @default(false) @map("email_verified")
|
|
150
|
+
image String? @db.String
|
|
151
|
+
|
|
152
|
+
Sessions Session[]
|
|
153
|
+
Accounts Account[]
|
|
154
|
+
|
|
155
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
156
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
157
|
+
|
|
158
|
+
@@map("user")
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
model Session {
|
|
162
|
+
id String @id @db.String(64)
|
|
163
|
+
|
|
164
|
+
expiresAt DateTime @map("expires_at")
|
|
165
|
+
token String @unique @db.String
|
|
166
|
+
ipAddress String? @map("ip_address") @db.String
|
|
167
|
+
userAgent String? @map("user_agent") @db.String
|
|
168
|
+
|
|
169
|
+
User User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
|
|
170
|
+
userId String @map("user_id") @db.String(64)
|
|
171
|
+
|
|
172
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
173
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
174
|
+
|
|
175
|
+
@@map("session")
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
model Account {
|
|
179
|
+
id String @id @db.String(64)
|
|
180
|
+
|
|
181
|
+
accountId String @map("account_id") @db.String(128)
|
|
182
|
+
providerId String @map("provider_id") @db.String(64)
|
|
183
|
+
|
|
184
|
+
User User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
|
|
185
|
+
userId String @map("user_id") @db.String(64)
|
|
186
|
+
|
|
187
|
+
accessToken String? @map("access_token") @db.String
|
|
188
|
+
refreshToken String? @map("refresh_token") @db.String
|
|
189
|
+
idToken String? @map("id_token") @db.String
|
|
190
|
+
accessTokenExpiresAt DateTime? @map("access_token_expires_at")
|
|
191
|
+
refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")
|
|
192
|
+
scope String? @db.String
|
|
193
|
+
password String? @db.String
|
|
194
|
+
|
|
195
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
196
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
197
|
+
|
|
198
|
+
@@map("account")
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
model Verification {
|
|
202
|
+
id String @id @db.String(64)
|
|
203
|
+
|
|
204
|
+
identifier String @db.String
|
|
205
|
+
value String @db.String
|
|
206
|
+
expiresAt DateTime @map("expires_at")
|
|
207
|
+
|
|
208
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
209
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
210
|
+
|
|
211
|
+
@@map("verification")
|
|
212
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -58,13 +58,6 @@ import { PrismaPg } from "@prisma/adapter-pg";
|
|
|
58
58
|
import { PrismaClient } from "./generated";
|
|
59
59
|
|
|
60
60
|
export function createPrismaClient(databaseUrl: string) {
|
|
61
|
-
const isAccelerate =
|
|
62
|
-
databaseUrl.startsWith("prisma://") ||
|
|
63
|
-
databaseUrl.startsWith("prisma+postgres://");
|
|
64
|
-
|
|
65
|
-
if (isAccelerate) {
|
|
66
|
-
return new PrismaClient({ accelerateUrl: databaseUrl });
|
|
67
|
-
}
|
|
68
61
|
return new PrismaClient({
|
|
69
62
|
adapter: new PrismaPg({
|
|
70
63
|
connectionString: databaseUrl,
|
|
@@ -74,3 +67,66 @@ export function createPrismaClient(databaseUrl: string) {
|
|
|
74
67
|
}),
|
|
75
68
|
});
|
|
76
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Postgres / Prisma error codes that signal a serialization conflict and are
|
|
73
|
+
* safe to retry.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* CockroachDB defaults to `SERIALIZABLE` isolation and aborts conflicting
|
|
77
|
+
* transactions with SQLSTATE `40001`. Prisma surfaces the same condition as
|
|
78
|
+
* `P2034` ("Transaction failed due to a write conflict or a deadlock"). Unlike
|
|
79
|
+
* some Postgres drivers, Prisma does not retry these automatically.
|
|
80
|
+
*/
|
|
81
|
+
const SERIALIZATION_RETRY_CODES = new Set(["40001", "P2034"]);
|
|
82
|
+
|
|
83
|
+
function isRetryableTransactionError(error: unknown): boolean {
|
|
84
|
+
if (typeof error !== "object" || error === null) return false;
|
|
85
|
+
const code = (error as { code?: unknown }).code;
|
|
86
|
+
return typeof code === "string" && SERIALIZATION_RETRY_CODES.has(code);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Runs a database operation, retrying it on CockroachDB serialization
|
|
91
|
+
* conflicts (`40001` / Prisma `P2034`) with exponential backoff.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* Wrap multi-statement transactions (`prisma.$transaction([...])`) and any
|
|
95
|
+
* write that may contend under `SERIALIZABLE` isolation. Non-retryable errors
|
|
96
|
+
* are rethrown immediately.
|
|
97
|
+
*
|
|
98
|
+
* @param fn - The operation to execute (and possibly re-execute).
|
|
99
|
+
* @param options.maxRetries - Maximum retry attempts after the first try (default 5).
|
|
100
|
+
* @param options.baseDelayMs - Base backoff delay in milliseconds (default 50).
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* await withTransactionRetry(() =>
|
|
105
|
+
* prisma.$transaction([
|
|
106
|
+
* prisma.book.updateMany({ ... }),
|
|
107
|
+
* prisma.book.updateMany({ ... }),
|
|
108
|
+
* ]),
|
|
109
|
+
* );
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export async function withTransactionRetry<T>(
|
|
113
|
+
fn: () => Promise<T>,
|
|
114
|
+
options: { maxRetries?: number; baseDelayMs?: number } = {},
|
|
115
|
+
): Promise<T> {
|
|
116
|
+
const { maxRetries = 5, baseDelayMs = 50 } = options;
|
|
117
|
+
let attempt = 0;
|
|
118
|
+
for (;;) {
|
|
119
|
+
try {
|
|
120
|
+
return await fn();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (attempt >= maxRetries || !isRetryableTransactionError(error)) {
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
const delay = baseDelayMs * 2 ** attempt;
|
|
126
|
+
await new Promise((resolve) => {
|
|
127
|
+
setTimeout(resolve, delay);
|
|
128
|
+
});
|
|
129
|
+
attempt += 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
-- CreateEnum
|
|
2
|
-
CREATE TYPE "Status" AS ENUM ('UNEXPORTED', 'UPDATED_RECENTLY', 'EXPORTED');
|
|
3
|
-
|
|
4
|
-
-- CreateTable
|
|
5
|
-
CREATE TABLE "users" (
|
|
6
|
-
"id" TEXT NOT NULL,
|
|
7
|
-
"email" TEXT NOT NULL,
|
|
8
|
-
"password" TEXT NOT NULL,
|
|
9
|
-
"verified" BOOLEAN NOT NULL DEFAULT false,
|
|
10
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
11
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
12
|
-
|
|
13
|
-
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
-- CreateTable
|
|
17
|
-
CREATE TABLE "profiles" (
|
|
18
|
-
"id" TEXT NOT NULL,
|
|
19
|
-
"name" TEXT,
|
|
20
|
-
"bio" TEXT,
|
|
21
|
-
"avatar_url" TEXT,
|
|
22
|
-
"user_id" TEXT NOT NULL,
|
|
23
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
24
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
25
|
-
|
|
26
|
-
CONSTRAINT "profiles_pkey" PRIMARY KEY ("id")
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
-- CreateTable
|
|
30
|
-
CREATE TABLE "login_histories" (
|
|
31
|
-
"id" TEXT NOT NULL,
|
|
32
|
-
"user_id" TEXT NOT NULL,
|
|
33
|
-
"ip_address" TEXT,
|
|
34
|
-
"user_agent" TEXT,
|
|
35
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
36
|
-
|
|
37
|
-
CONSTRAINT "login_histories_pkey" PRIMARY KEY ("id")
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
-- CreateTable
|
|
41
|
-
CREATE TABLE "categories" (
|
|
42
|
-
"id" SERIAL NOT NULL,
|
|
43
|
-
"name" TEXT NOT NULL,
|
|
44
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
45
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
46
|
-
"user_id" TEXT NOT NULL,
|
|
47
|
-
|
|
48
|
-
CONSTRAINT "categories_pkey" PRIMARY KEY ("id")
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
-- CreateTable
|
|
52
|
-
CREATE TABLE "news" (
|
|
53
|
-
"id" SERIAL NOT NULL,
|
|
54
|
-
"title" TEXT NOT NULL,
|
|
55
|
-
"url" TEXT NOT NULL,
|
|
56
|
-
"quote" TEXT,
|
|
57
|
-
"status" "Status" NOT NULL DEFAULT 'UNEXPORTED',
|
|
58
|
-
"category_id" INTEGER NOT NULL,
|
|
59
|
-
"userId" TEXT NOT NULL,
|
|
60
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
61
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
62
|
-
|
|
63
|
-
CONSTRAINT "news_pkey" PRIMARY KEY ("id")
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
-- CreateTable
|
|
67
|
-
CREATE TABLE "contents" (
|
|
68
|
-
"id" SERIAL NOT NULL,
|
|
69
|
-
"title" TEXT NOT NULL,
|
|
70
|
-
"url" TEXT NOT NULL,
|
|
71
|
-
"quote" TEXT,
|
|
72
|
-
"status" "Status" NOT NULL DEFAULT 'UNEXPORTED',
|
|
73
|
-
"user_id" TEXT NOT NULL,
|
|
74
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
75
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
76
|
-
|
|
77
|
-
CONSTRAINT "contents_pkey" PRIMARY KEY ("id")
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
-- CreateIndex
|
|
81
|
-
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
|
|
82
|
-
|
|
83
|
-
-- CreateIndex
|
|
84
|
-
CREATE UNIQUE INDEX "profiles_user_id_key" ON "profiles"("user_id");
|
|
85
|
-
|
|
86
|
-
-- CreateIndex
|
|
87
|
-
CREATE UNIQUE INDEX "categories_name_key" ON "categories"("name");
|
|
88
|
-
|
|
89
|
-
-- AddForeignKey
|
|
90
|
-
ALTER TABLE "profiles" ADD CONSTRAINT "profiles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
91
|
-
|
|
92
|
-
-- AddForeignKey
|
|
93
|
-
ALTER TABLE "login_histories" ADD CONSTRAINT "login_histories_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
94
|
-
|
|
95
|
-
-- AddForeignKey
|
|
96
|
-
ALTER TABLE "categories" ADD CONSTRAINT "categories_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
97
|
-
|
|
98
|
-
-- AddForeignKey
|
|
99
|
-
ALTER TABLE "news" ADD CONSTRAINT "news_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "categories"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
100
|
-
|
|
101
|
-
-- AddForeignKey
|
|
102
|
-
ALTER TABLE "news" ADD CONSTRAINT "news_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
103
|
-
|
|
104
|
-
-- AddForeignKey
|
|
105
|
-
ALTER TABLE "contents" ADD CONSTRAINT "contents_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- A unique constraint covering the columns `[name,user_id]` on the table `categories` will be added. If there are existing duplicate values, this will fail.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
-- DropIndex
|
|
8
|
-
DROP INDEX "categories_name_key";
|
|
9
|
-
|
|
10
|
-
-- CreateIndex
|
|
11
|
-
CREATE UNIQUE INDEX "categories_name_user_id_key" ON "categories"("name", "user_id");
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- A unique constraint covering the columns `[name]` on the table `profiles` will be added. If there are existing duplicate values, this will fail.
|
|
5
|
-
- A unique constraint covering the columns `[username]` on the table `users` will be added. If there are existing duplicate values, this will fail.
|
|
6
|
-
- Made the column `name` on table `profiles` required. This step will fail if there are existing NULL values in that column.
|
|
7
|
-
- Added the required column `username` to the `users` table without a default value. This is not possible if the table is not empty.
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
-- CreateEnum
|
|
11
|
-
CREATE TYPE "Scope" AS ENUM ('PUBLIC', 'PRIVATE');
|
|
12
|
-
|
|
13
|
-
-- AlterTable
|
|
14
|
-
ALTER TABLE "profiles" ALTER COLUMN "name" SET NOT NULL;
|
|
15
|
-
|
|
16
|
-
-- AlterTable
|
|
17
|
-
ALTER TABLE "users" ADD COLUMN "scope" "Scope" NOT NULL DEFAULT 'PUBLIC',
|
|
18
|
-
ADD COLUMN "username" TEXT NOT NULL;
|
|
19
|
-
|
|
20
|
-
-- CreateIndex
|
|
21
|
-
CREATE UNIQUE INDEX "profiles_name_key" ON "profiles"("name");
|
|
22
|
-
|
|
23
|
-
-- CreateIndex
|
|
24
|
-
CREATE UNIQUE INDEX "users_username_key" ON "users"("username");
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- You are about to drop the column `verified` on the `users` table. All the data in the column will be lost.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
-- AlterEnum
|
|
8
|
-
ALTER TYPE "Role" ADD VALUE 'UNAUTHORIZED';
|
|
9
|
-
|
|
10
|
-
-- AlterTable
|
|
11
|
-
ALTER TABLE "users" DROP COLUMN "verified";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
-- CreateTable
|
|
2
|
-
CREATE TABLE "images" (
|
|
3
|
-
"id" TEXT NOT NULL,
|
|
4
|
-
"status" "Status" NOT NULL DEFAULT 'UNEXPORTED',
|
|
5
|
-
"user_id" TEXT NOT NULL,
|
|
6
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
8
|
-
|
|
9
|
-
CONSTRAINT "images_pkey" PRIMARY KEY ("id")
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
-- AddForeignKey
|
|
13
|
-
ALTER TABLE "images" ADD CONSTRAINT "images_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- The values [UNAUTHORIZED] on the enum `Role` will be removed. If these variants are still used in the database, this will fail.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
-- AlterEnum
|
|
8
|
-
BEGIN;
|
|
9
|
-
CREATE TYPE "Role_new" AS ENUM ('ADMIN', 'EDITOR', 'VIEWER');
|
|
10
|
-
ALTER TABLE "users" ALTER COLUMN "role" DROP DEFAULT;
|
|
11
|
-
ALTER TABLE "users" ALTER COLUMN "role" TYPE "Role_new" USING ("role"::text::"Role_new");
|
|
12
|
-
ALTER TYPE "Role" RENAME TO "Role_old";
|
|
13
|
-
ALTER TYPE "Role_new" RENAME TO "Role";
|
|
14
|
-
DROP TYPE "Role_old";
|
|
15
|
-
ALTER TABLE "users" ALTER COLUMN "role" SET DEFAULT 'VIEWER';
|
|
16
|
-
COMMIT;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- The values [EDITOR] on the enum `Role` will be removed. If these variants are still used in the database, this will fail.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
-- AlterEnum
|
|
8
|
-
BEGIN;
|
|
9
|
-
CREATE TYPE "Role_new" AS ENUM ('ADMIN', 'VIEWER', 'UNAUTHORIZED');
|
|
10
|
-
ALTER TABLE "users" ALTER COLUMN "role" DROP DEFAULT;
|
|
11
|
-
ALTER TABLE "users" ALTER COLUMN "role" TYPE "Role_new" USING ("role"::text::"Role_new");
|
|
12
|
-
ALTER TYPE "Role" RENAME TO "Role_old";
|
|
13
|
-
ALTER TYPE "Role_new" RENAME TO "Role";
|
|
14
|
-
DROP TYPE "Role_old";
|
|
15
|
-
ALTER TABLE "users" ALTER COLUMN "role" SET DEFAULT 'UNAUTHORIZED';
|
|
16
|
-
COMMIT;
|
|
17
|
-
|
|
18
|
-
-- AlterTable
|
|
19
|
-
ALTER TABLE "users" ALTER COLUMN "role" SET DEFAULT 'UNAUTHORIZED';
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
-- CreateTable
|
|
2
|
-
CREATE TABLE "st_contents" (
|
|
3
|
-
"title" TEXT NOT NULL,
|
|
4
|
-
"markdown" TEXT NOT NULL,
|
|
5
|
-
"uint8ArrayImage" BYTEA NOT NULL,
|
|
6
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
8
|
-
|
|
9
|
-
CONSTRAINT "st_contents_pkey" PRIMARY KEY ("title")
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
-- CreateTable
|
|
13
|
-
CREATE TABLE "st_books" (
|
|
14
|
-
"title" TEXT NOT NULL,
|
|
15
|
-
"markdown" TEXT NOT NULL,
|
|
16
|
-
"uint8ArrayImage" BYTEA NOT NULL,
|
|
17
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
18
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
19
|
-
|
|
20
|
-
CONSTRAINT "st_books_pkey" PRIMARY KEY ("title")
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
-- CreateIndex
|
|
24
|
-
CREATE UNIQUE INDEX "st_contents_title_key" ON "st_contents"("title");
|
|
25
|
-
|
|
26
|
-
-- CreateIndex
|
|
27
|
-
CREATE UNIQUE INDEX "st_books_title_key" ON "st_books"("title");
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- You are about to drop the `login_histories` table. If the table is not empty, all the data it contains will be lost.
|
|
5
|
-
- You are about to drop the `profiles` table. If the table is not empty, all the data it contains will be lost.
|
|
6
|
-
- You are about to drop the `users` table. If the table is not empty, all the data it contains will be lost.
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
-- DropForeignKey
|
|
10
|
-
ALTER TABLE "categories" DROP CONSTRAINT "categories_user_id_fkey";
|
|
11
|
-
|
|
12
|
-
-- DropForeignKey
|
|
13
|
-
ALTER TABLE "contents" DROP CONSTRAINT "contents_user_id_fkey";
|
|
14
|
-
|
|
15
|
-
-- DropForeignKey
|
|
16
|
-
ALTER TABLE "images" DROP CONSTRAINT "images_user_id_fkey";
|
|
17
|
-
|
|
18
|
-
-- DropForeignKey
|
|
19
|
-
ALTER TABLE "login_histories" DROP CONSTRAINT "login_histories_user_id_fkey";
|
|
20
|
-
|
|
21
|
-
-- DropForeignKey
|
|
22
|
-
ALTER TABLE "news" DROP CONSTRAINT "news_userId_fkey";
|
|
23
|
-
|
|
24
|
-
-- DropForeignKey
|
|
25
|
-
ALTER TABLE "profiles" DROP CONSTRAINT "profiles_user_id_fkey";
|
|
26
|
-
|
|
27
|
-
-- DropTable
|
|
28
|
-
DROP TABLE "login_histories";
|
|
29
|
-
|
|
30
|
-
-- DropTable
|
|
31
|
-
DROP TABLE "profiles";
|
|
32
|
-
|
|
33
|
-
-- DropTable
|
|
34
|
-
DROP TABLE "users";
|
|
35
|
-
|
|
36
|
-
-- DropEnum
|
|
37
|
-
DROP TYPE "Role";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- Added the required column `content_type` to the `images` table without a default value. This is not possible if the table is not empty.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
-- AlterTable
|
|
8
|
-
ALTER TABLE "images" ADD COLUMN "content_type" TEXT NOT NULL,
|
|
9
|
-
ADD COLUMN "deleted_at" TIMESTAMP(3),
|
|
10
|
-
ADD COLUMN "description" TEXT,
|
|
11
|
-
ADD COLUMN "file_size" INTEGER,
|
|
12
|
-
ADD COLUMN "height" INTEGER,
|
|
13
|
-
ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
14
|
-
ADD COLUMN "width" INTEGER;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
-- CreateTable
|
|
2
|
-
CREATE TABLE "st_images" (
|
|
3
|
-
"id" TEXT NOT NULL,
|
|
4
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
5
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
6
|
-
"content_type" TEXT NOT NULL,
|
|
7
|
-
"file_size" INTEGER,
|
|
8
|
-
"width" INTEGER,
|
|
9
|
-
"height" INTEGER,
|
|
10
|
-
"tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
11
|
-
"description" TEXT,
|
|
12
|
-
|
|
13
|
-
CONSTRAINT "st_images_pkey" PRIMARY KEY ("id")
|
|
14
|
-
);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- A unique constraint covering the columns `[name]` on the table `categories` will be added. If there are existing duplicate values, this will fail.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
-- CreateTable
|
|
8
|
-
CREATE TABLE "st_news" (
|
|
9
|
-
"id" SERIAL NOT NULL,
|
|
10
|
-
"url" TEXT NOT NULL,
|
|
11
|
-
"title" TEXT NOT NULL,
|
|
12
|
-
"quote" TEXT,
|
|
13
|
-
"category_id" INTEGER NOT NULL,
|
|
14
|
-
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
15
|
-
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
16
|
-
|
|
17
|
-
CONSTRAINT "st_news_pkey" PRIMARY KEY ("url")
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
-- CreateIndex
|
|
21
|
-
CREATE UNIQUE INDEX "st_news_url_key" ON "st_news"("url");
|
|
22
|
-
|
|
23
|
-
-- CreateIndex
|
|
24
|
-
CREATE UNIQUE INDEX "categories_name_key" ON "categories"("name");
|
|
25
|
-
|
|
26
|
-
-- AddForeignKey
|
|
27
|
-
ALTER TABLE "st_news" ADD CONSTRAINT "st_news_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "categories"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|