@dimah-s3/db 2.0.0-beta.0 → 2.0.0-beta.2
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/README.md +3 -3
- package/dist/adapters/drizzle.d.ts +2 -1
- package/dist/adapters/drizzle.d.ts.map +1 -1
- package/dist/cli.d.ts +8 -9
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +42 -103
- package/dist/cli.js.map +1 -1
- package/dist/client/db-client.d.ts +1 -1
- package/dist/client/db-client.d.ts.map +1 -1
- package/dist/client/db-object-source.d.ts +5 -4
- package/dist/client/db-object-source.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +27 -12
- package/dist/client/index.js.map +1 -1
- package/dist/drizzle/mysql.d.ts +46 -13
- package/dist/drizzle/mysql.d.ts.map +1 -1
- package/dist/drizzle/mysql.js +15 -18
- package/dist/drizzle/mysql.js.map +1 -1
- package/dist/drizzle/pg.d.ts +44 -13
- package/dist/drizzle/pg.d.ts.map +1 -1
- package/dist/drizzle/pg.js +17 -17
- package/dist/drizzle/pg.js.map +1 -1
- package/dist/drizzle/shared.d.ts +4 -13
- package/dist/drizzle/shared.d.ts.map +1 -1
- package/dist/drizzle/sqlite.d.ts +46 -13
- package/dist/drizzle/sqlite.d.ts.map +1 -1
- package/dist/drizzle/sqlite.js +17 -17
- package/dist/drizzle/sqlite.js.map +1 -1
- package/dist/folder-path.d.ts +9 -2
- package/dist/folder-path.d.ts.map +1 -1
- package/dist/fuma-db.d.ts +10 -30
- package/dist/fuma-db.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +372 -231
- package/dist/index.js.map +1 -1
- package/dist/plugin/create-database-endpoints.d.ts +38 -18
- package/dist/plugin/create-database-endpoints.d.ts.map +1 -1
- package/dist/plugin/create-database-lifecycle-hooks.d.ts +1 -1
- package/dist/plugin/create-database-lifecycle-hooks.d.ts.map +1 -1
- package/dist/plugin/db.d.ts.map +1 -1
- package/dist/plugin/object-access.d.ts +1 -1
- package/dist/plugin/object-access.d.ts.map +1 -1
- package/dist/plugin/public-stores.d.ts +4 -7
- package/dist/plugin/public-stores.d.ts.map +1 -1
- package/dist/plugin/schemas.d.ts +21 -12
- package/dist/plugin/schemas.d.ts.map +1 -1
- package/dist/plugin/to-db-client-object.d.ts.map +1 -1
- package/dist/schema/{v2.d.ts → schema.d.ts} +23 -13
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/store/create-db-store.d.ts +2 -2
- package/dist/store/folder-store.d.ts +41 -14
- package/dist/store/folder-store.d.ts.map +1 -1
- package/dist/store/list-cursor.d.ts +1 -1
- package/dist/store/list-cursor.d.ts.map +1 -1
- package/dist/store/map-row.d.ts +2 -2
- package/dist/store/map-row.d.ts.map +1 -1
- package/dist/store/object-store.d.ts +9 -9
- package/dist/store/object-store.d.ts.map +1 -1
- package/dist/store/schema-version.d.ts +1 -1
- package/dist/types/client.d.ts +47 -18
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +6 -1
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/storage-object.d.ts +8 -7
- package/dist/types/storage-object.d.ts.map +1 -1
- package/package.json +9 -6
- package/prisma/dimah-s3.prisma +14 -13
- package/sql/mysql.sql +12 -11
- package/sql/pg.sql +10 -10
- package/sql/sqlite.sql +10 -9
- package/src/drizzle/mysql.ts +175 -0
- package/src/drizzle/pg.ts +146 -0
- package/src/drizzle/sqlite.ts +150 -0
- package/dist/schema/v1.d.ts +0 -24
- package/dist/schema/v1.d.ts.map +0 -1
- package/dist/schema/v2.d.ts.map +0 -1
- package/sql/upgrade/1.0.0-2.0.0/mysql.sql +0 -71
- package/sql/upgrade/1.0.0-2.0.0/pg.sql +0 -47
- package/sql/upgrade/1.0.0-2.0.0/sqlite.sql +0 -119
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle schema for @dimah-s3/db on MySQL 8. Copy this file into your app
|
|
3
|
+
* (`db/schema.ts`) to own the tables and add columns. Keep the table names,
|
|
4
|
+
* the column names, and the `dimahS3Tables` keys: the adapter finds the
|
|
5
|
+
* tables by those keys. A column you add must be nullable or have a default.
|
|
6
|
+
* The plugin does not read or write it.
|
|
7
|
+
*
|
|
8
|
+
* Import `dimahS3Tables` from `@dimah-s3/db/drizzle/mysql` when the tables
|
|
9
|
+
* stay as they are. `drizzle-kit` then follows that import, and a later push
|
|
10
|
+
* drops a column that is not part of it.
|
|
11
|
+
*
|
|
12
|
+
* Columns, collations and indexes match `sql/mysql.sql`, including the
|
|
13
|
+
* prefix indexes on `key`, `folder`, `path` and `parent`. Keys, folders and
|
|
14
|
+
* scopes compare byte for byte (`utf8mb4_bin`), and file names
|
|
15
|
+
* case-insensitively (`utf8mb4_unicode_ci`). Requires `drizzle-orm` and
|
|
16
|
+
* `@paralleldrive/cuid2`.
|
|
17
|
+
*/
|
|
18
|
+
import { createId } from "@paralleldrive/cuid2";
|
|
19
|
+
import { sql } from "drizzle-orm";
|
|
20
|
+
import {
|
|
21
|
+
bigint,
|
|
22
|
+
datetime,
|
|
23
|
+
index,
|
|
24
|
+
json,
|
|
25
|
+
mysqlTable,
|
|
26
|
+
text,
|
|
27
|
+
uniqueIndex,
|
|
28
|
+
varchar,
|
|
29
|
+
type MySqlColumn,
|
|
30
|
+
} from "drizzle-orm/mysql-core";
|
|
31
|
+
|
|
32
|
+
type StorageObjectStatus = "pending" | "active" | "deleted" | "purging";
|
|
33
|
+
|
|
34
|
+
const SCHEMA_VERSION = "2.1.0";
|
|
35
|
+
|
|
36
|
+
/** Collation of every text column but `filename`: byte for byte. */
|
|
37
|
+
const BINARY = "utf8mb4_bin";
|
|
38
|
+
|
|
39
|
+
function id() {
|
|
40
|
+
return string("id")
|
|
41
|
+
.primaryKey()
|
|
42
|
+
.$defaultFn(() => createId());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function string(name: string, length = 255) {
|
|
46
|
+
return varchar(name, { length }).collate(BINARY);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function timestamp(name: string) {
|
|
50
|
+
return datetime(name, { mode: "date", fsp: 3 });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function timestampNow(name: string) {
|
|
54
|
+
return timestamp(name)
|
|
55
|
+
.notNull()
|
|
56
|
+
.default(sql`CURRENT_TIMESTAMP(3)`)
|
|
57
|
+
.$defaultFn(() => new Date());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function byteCount(name: string) {
|
|
61
|
+
return bigint(name, { mode: "number" });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** An index on the first `length` characters of a long column. */
|
|
65
|
+
function prefix(column: MySqlColumn, length: number) {
|
|
66
|
+
return sql`${column}(${sql.raw(String(length))})`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The `storage_object` table: one row per tracked object. */
|
|
70
|
+
export const storageObject = mysqlTable(
|
|
71
|
+
"storage_object",
|
|
72
|
+
{
|
|
73
|
+
id: id(),
|
|
74
|
+
scope: string("scope").notNull(),
|
|
75
|
+
bucket: string("bucket").notNull(),
|
|
76
|
+
key: string("key", 1024).notNull(),
|
|
77
|
+
route: string("route").notNull(),
|
|
78
|
+
folderId: string("folder_id"),
|
|
79
|
+
filename: varchar("filename", { length: 255 })
|
|
80
|
+
.collate("utf8mb4_unicode_ci")
|
|
81
|
+
.notNull(),
|
|
82
|
+
contentType: string("content_type"),
|
|
83
|
+
size: byteCount("size"),
|
|
84
|
+
declaredSize: byteCount("declared_size"),
|
|
85
|
+
eTag: string("e_tag"),
|
|
86
|
+
status: string("status", 16).$type<StorageObjectStatus>().notNull(),
|
|
87
|
+
s3Metadata: json("s3_metadata").$type<Record<string, string>>(),
|
|
88
|
+
attributes: json("attributes"),
|
|
89
|
+
acl: string("acl"),
|
|
90
|
+
uploadId: text("upload_id").collate(BINARY),
|
|
91
|
+
uploadToken: string("upload_token", 64),
|
|
92
|
+
expiresAt: timestamp("expires_at"),
|
|
93
|
+
confirmedAt: timestamp("confirmed_at"),
|
|
94
|
+
createdAt: timestampNow("created_at"),
|
|
95
|
+
updatedAt: timestampNow("updated_at"),
|
|
96
|
+
deletedAt: timestamp("deleted_at"),
|
|
97
|
+
},
|
|
98
|
+
(table) => [
|
|
99
|
+
uniqueIndex("storage_object_bucket_key_uk").on(
|
|
100
|
+
table.bucket,
|
|
101
|
+
prefix(table.key, 512),
|
|
102
|
+
),
|
|
103
|
+
index("storage_object_scope_folder_idx").on(
|
|
104
|
+
table.scope,
|
|
105
|
+
table.status,
|
|
106
|
+
table.folderId,
|
|
107
|
+
table.createdAt,
|
|
108
|
+
),
|
|
109
|
+
index("storage_object_scope_updated_idx").on(
|
|
110
|
+
table.scope,
|
|
111
|
+
table.status,
|
|
112
|
+
table.updatedAt,
|
|
113
|
+
),
|
|
114
|
+
index("storage_object_scope_filename_idx").on(
|
|
115
|
+
table.scope,
|
|
116
|
+
table.status,
|
|
117
|
+
table.filename,
|
|
118
|
+
),
|
|
119
|
+
index("storage_object_scope_size_idx").on(
|
|
120
|
+
table.scope,
|
|
121
|
+
table.status,
|
|
122
|
+
table.size,
|
|
123
|
+
),
|
|
124
|
+
index("storage_object_status_expires_idx").on(
|
|
125
|
+
table.status,
|
|
126
|
+
table.expiresAt,
|
|
127
|
+
),
|
|
128
|
+
],
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
/** The `storage_folder` table: one row per folder, so empty folders list. */
|
|
132
|
+
export const storageFolder = mysqlTable(
|
|
133
|
+
"storage_folder",
|
|
134
|
+
{
|
|
135
|
+
id: id(),
|
|
136
|
+
scope: string("scope").notNull(),
|
|
137
|
+
/** `""` is the root. */
|
|
138
|
+
parentId: string("parent_id").notNull().default(""),
|
|
139
|
+
name: string("name").notNull(),
|
|
140
|
+
path: string("path", 1024).notNull(),
|
|
141
|
+
createdAt: timestampNow("created_at"),
|
|
142
|
+
updatedAt: timestampNow("updated_at"),
|
|
143
|
+
},
|
|
144
|
+
(table) => [
|
|
145
|
+
uniqueIndex("storage_folder_scope_path_uk").on(
|
|
146
|
+
table.scope,
|
|
147
|
+
prefix(table.path, 512),
|
|
148
|
+
),
|
|
149
|
+
uniqueIndex("storage_folder_scope_parent_name_uk").on(
|
|
150
|
+
table.scope,
|
|
151
|
+
table.parentId,
|
|
152
|
+
table.name,
|
|
153
|
+
),
|
|
154
|
+
],
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The FumaDB settings table. The Drizzle adapter reads the schema version
|
|
159
|
+
* from the default of its `version` column, which is stored as `value`.
|
|
160
|
+
*/
|
|
161
|
+
export const dimahS3Settings = mysqlTable("private_dimah_s3_settings", {
|
|
162
|
+
key: string("key").primaryKey(),
|
|
163
|
+
version: text("value").collate(BINARY).notNull().default(SCHEMA_VERSION),
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Every @dimah-s3/db table. Spread it into your Drizzle schema and keep its
|
|
168
|
+
* keys, because the FumaDB Drizzle adapter finds tables by them:
|
|
169
|
+
* `drizzle({ client, relations: defineRelations({ ...dimahS3Tables }) })`.
|
|
170
|
+
*/
|
|
171
|
+
export const dimahS3Tables = {
|
|
172
|
+
storageObject,
|
|
173
|
+
storageFolder,
|
|
174
|
+
private_dimah_s3_settings: dimahS3Settings,
|
|
175
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle schema for @dimah-s3/db on PostgreSQL. Copy this file into your
|
|
3
|
+
* app (`db/schema.ts`) to own the tables and add columns. Keep the table
|
|
4
|
+
* names, the column names, and the `dimahS3Tables` keys: the adapter finds
|
|
5
|
+
* the tables by those keys. A column you add must be nullable or have a
|
|
6
|
+
* default. The plugin does not read or write it.
|
|
7
|
+
*
|
|
8
|
+
* Import `dimahS3Tables` from `@dimah-s3/db/drizzle/pg` when the tables stay
|
|
9
|
+
* as they are. `drizzle-kit` then follows that import, and a later push
|
|
10
|
+
* drops a column that is not part of it.
|
|
11
|
+
*
|
|
12
|
+
* Matches `sql/pg.sql`. Requires `drizzle-orm` and `@paralleldrive/cuid2`.
|
|
13
|
+
*/
|
|
14
|
+
import { createId } from "@paralleldrive/cuid2";
|
|
15
|
+
import { sql } from "drizzle-orm";
|
|
16
|
+
import {
|
|
17
|
+
bigint,
|
|
18
|
+
index,
|
|
19
|
+
json,
|
|
20
|
+
pgTable,
|
|
21
|
+
text,
|
|
22
|
+
timestamp,
|
|
23
|
+
unique,
|
|
24
|
+
varchar,
|
|
25
|
+
} from "drizzle-orm/pg-core";
|
|
26
|
+
|
|
27
|
+
type StorageObjectStatus = "pending" | "active" | "deleted" | "purging";
|
|
28
|
+
|
|
29
|
+
const SCHEMA_VERSION = "2.1.0";
|
|
30
|
+
|
|
31
|
+
function id() {
|
|
32
|
+
return varchar("id", { length: 255 })
|
|
33
|
+
.primaryKey()
|
|
34
|
+
.$defaultFn(() => createId());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function timestampNow(name: string) {
|
|
38
|
+
return timestamp(name)
|
|
39
|
+
.notNull()
|
|
40
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
41
|
+
.$defaultFn(() => new Date());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function byteCount(name: string) {
|
|
45
|
+
return bigint(name, { mode: "number" });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The `storage_object` table: one row per tracked object. */
|
|
49
|
+
export const storageObject = pgTable(
|
|
50
|
+
"storage_object",
|
|
51
|
+
{
|
|
52
|
+
id: id(),
|
|
53
|
+
scope: text("scope").notNull(),
|
|
54
|
+
bucket: text("bucket").notNull(),
|
|
55
|
+
key: text("key").notNull(),
|
|
56
|
+
route: text("route").notNull(),
|
|
57
|
+
folderId: text("folder_id"),
|
|
58
|
+
filename: text("filename").notNull(),
|
|
59
|
+
contentType: text("content_type"),
|
|
60
|
+
size: byteCount("size"),
|
|
61
|
+
declaredSize: byteCount("declared_size"),
|
|
62
|
+
eTag: text("e_tag"),
|
|
63
|
+
status: text("status").$type<StorageObjectStatus>().notNull(),
|
|
64
|
+
s3Metadata: json("s3_metadata").$type<Record<string, string>>(),
|
|
65
|
+
attributes: json("attributes"),
|
|
66
|
+
acl: text("acl"),
|
|
67
|
+
uploadId: text("upload_id"),
|
|
68
|
+
uploadToken: text("upload_token"),
|
|
69
|
+
expiresAt: timestamp("expires_at"),
|
|
70
|
+
confirmedAt: timestamp("confirmed_at"),
|
|
71
|
+
createdAt: timestampNow("created_at"),
|
|
72
|
+
updatedAt: timestampNow("updated_at"),
|
|
73
|
+
deletedAt: timestamp("deleted_at"),
|
|
74
|
+
},
|
|
75
|
+
(table) => [
|
|
76
|
+
unique("storage_object_bucket_key_uk").on(table.bucket, table.key),
|
|
77
|
+
index("storage_object_scope_folder_idx").on(
|
|
78
|
+
table.scope,
|
|
79
|
+
table.status,
|
|
80
|
+
table.folderId,
|
|
81
|
+
table.createdAt,
|
|
82
|
+
),
|
|
83
|
+
index("storage_object_scope_updated_idx").on(
|
|
84
|
+
table.scope,
|
|
85
|
+
table.status,
|
|
86
|
+
table.updatedAt,
|
|
87
|
+
),
|
|
88
|
+
index("storage_object_scope_filename_idx").on(
|
|
89
|
+
table.scope,
|
|
90
|
+
table.status,
|
|
91
|
+
table.filename,
|
|
92
|
+
),
|
|
93
|
+
index("storage_object_scope_size_idx").on(
|
|
94
|
+
table.scope,
|
|
95
|
+
table.status,
|
|
96
|
+
table.size,
|
|
97
|
+
),
|
|
98
|
+
index("storage_object_status_expires_idx").on(
|
|
99
|
+
table.status,
|
|
100
|
+
table.expiresAt,
|
|
101
|
+
),
|
|
102
|
+
],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
/** The `storage_folder` table: one row per folder, so empty folders list. */
|
|
106
|
+
export const storageFolder = pgTable(
|
|
107
|
+
"storage_folder",
|
|
108
|
+
{
|
|
109
|
+
id: id(),
|
|
110
|
+
scope: text("scope").notNull(),
|
|
111
|
+
/** `""` is the root. */
|
|
112
|
+
parentId: text("parent_id").notNull().default(""),
|
|
113
|
+
name: text("name").notNull(),
|
|
114
|
+
path: text("path").notNull(),
|
|
115
|
+
createdAt: timestampNow("created_at"),
|
|
116
|
+
updatedAt: timestampNow("updated_at"),
|
|
117
|
+
},
|
|
118
|
+
(table) => [
|
|
119
|
+
unique("storage_folder_scope_path_uk").on(table.scope, table.path),
|
|
120
|
+
unique("storage_folder_scope_parent_name_uk").on(
|
|
121
|
+
table.scope,
|
|
122
|
+
table.parentId,
|
|
123
|
+
table.name,
|
|
124
|
+
),
|
|
125
|
+
],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The FumaDB settings table. The Drizzle adapter reads the schema version
|
|
130
|
+
* from the default of its `version` column, which is stored as `value`.
|
|
131
|
+
*/
|
|
132
|
+
export const dimahS3Settings = pgTable("private_dimah_s3_settings", {
|
|
133
|
+
key: varchar("key", { length: 255 }).primaryKey(),
|
|
134
|
+
version: text("value").notNull().default(SCHEMA_VERSION),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Every @dimah-s3/db table. Spread it into your Drizzle schema and keep its
|
|
139
|
+
* keys, because the FumaDB Drizzle adapter finds tables by them:
|
|
140
|
+
* `drizzle({ client, relations: defineRelations({ ...dimahS3Tables }) })`.
|
|
141
|
+
*/
|
|
142
|
+
export const dimahS3Tables = {
|
|
143
|
+
storageObject,
|
|
144
|
+
storageFolder,
|
|
145
|
+
private_dimah_s3_settings: dimahS3Settings,
|
|
146
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle schema for @dimah-s3/db on SQLite. Copy this file into your app
|
|
3
|
+
* (`db/schema.ts`) to own the tables and add columns. Keep the table names,
|
|
4
|
+
* the column names, and the `dimahS3Tables` keys: the adapter finds the
|
|
5
|
+
* tables by those keys. A column you add must be nullable or have a default.
|
|
6
|
+
* The plugin does not read or write it.
|
|
7
|
+
*
|
|
8
|
+
* Import `dimahS3Tables` from `@dimah-s3/db/drizzle/sqlite` when the tables
|
|
9
|
+
* stay as they are. `drizzle-kit` then follows that import, and a later push
|
|
10
|
+
* drops a column that is not part of it.
|
|
11
|
+
*
|
|
12
|
+
* Timestamps are epoch milliseconds and sizes are integers, matching
|
|
13
|
+
* `sql/sqlite.sql`. Requires `drizzle-orm` and `@paralleldrive/cuid2`.
|
|
14
|
+
*/
|
|
15
|
+
import { createId } from "@paralleldrive/cuid2";
|
|
16
|
+
import { sql } from "drizzle-orm";
|
|
17
|
+
import {
|
|
18
|
+
index,
|
|
19
|
+
integer,
|
|
20
|
+
sqliteTable,
|
|
21
|
+
text,
|
|
22
|
+
uniqueIndex,
|
|
23
|
+
} from "drizzle-orm/sqlite-core";
|
|
24
|
+
|
|
25
|
+
type StorageObjectStatus = "pending" | "active" | "deleted" | "purging";
|
|
26
|
+
|
|
27
|
+
const SCHEMA_VERSION = "2.1.0";
|
|
28
|
+
|
|
29
|
+
function id() {
|
|
30
|
+
return text("id")
|
|
31
|
+
.primaryKey()
|
|
32
|
+
.$defaultFn(() => createId());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function timestamp(name: string) {
|
|
36
|
+
return integer(name, { mode: "timestamp_ms" });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function timestampNow(name: string) {
|
|
40
|
+
return timestamp(name)
|
|
41
|
+
.notNull()
|
|
42
|
+
.default(sql`(strftime('%s', 'now') * 1000)`)
|
|
43
|
+
.$defaultFn(() => new Date());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function byteCount(name: string) {
|
|
47
|
+
return integer(name, { mode: "number" });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The `storage_object` table: one row per tracked object. */
|
|
51
|
+
export const storageObject = sqliteTable(
|
|
52
|
+
"storage_object",
|
|
53
|
+
{
|
|
54
|
+
id: id(),
|
|
55
|
+
scope: text("scope").notNull(),
|
|
56
|
+
bucket: text("bucket").notNull(),
|
|
57
|
+
key: text("key").notNull(),
|
|
58
|
+
route: text("route").notNull(),
|
|
59
|
+
folderId: text("folder_id"),
|
|
60
|
+
filename: text("filename").notNull(),
|
|
61
|
+
contentType: text("content_type"),
|
|
62
|
+
size: byteCount("size"),
|
|
63
|
+
declaredSize: byteCount("declared_size"),
|
|
64
|
+
eTag: text("e_tag"),
|
|
65
|
+
status: text("status").$type<StorageObjectStatus>().notNull(),
|
|
66
|
+
s3Metadata: text("s3_metadata", { mode: "json" }).$type<
|
|
67
|
+
Record<string, string>
|
|
68
|
+
>(),
|
|
69
|
+
attributes: text("attributes", { mode: "json" }),
|
|
70
|
+
acl: text("acl"),
|
|
71
|
+
uploadId: text("upload_id"),
|
|
72
|
+
uploadToken: text("upload_token"),
|
|
73
|
+
expiresAt: timestamp("expires_at"),
|
|
74
|
+
confirmedAt: timestamp("confirmed_at"),
|
|
75
|
+
createdAt: timestampNow("created_at"),
|
|
76
|
+
updatedAt: timestampNow("updated_at"),
|
|
77
|
+
deletedAt: timestamp("deleted_at"),
|
|
78
|
+
},
|
|
79
|
+
(table) => [
|
|
80
|
+
uniqueIndex("storage_object_bucket_key_uk").on(table.bucket, table.key),
|
|
81
|
+
index("storage_object_scope_folder_idx").on(
|
|
82
|
+
table.scope,
|
|
83
|
+
table.status,
|
|
84
|
+
table.folderId,
|
|
85
|
+
table.createdAt,
|
|
86
|
+
),
|
|
87
|
+
index("storage_object_scope_updated_idx").on(
|
|
88
|
+
table.scope,
|
|
89
|
+
table.status,
|
|
90
|
+
table.updatedAt,
|
|
91
|
+
),
|
|
92
|
+
index("storage_object_scope_filename_idx").on(
|
|
93
|
+
table.scope,
|
|
94
|
+
table.status,
|
|
95
|
+
table.filename,
|
|
96
|
+
),
|
|
97
|
+
index("storage_object_scope_size_idx").on(
|
|
98
|
+
table.scope,
|
|
99
|
+
table.status,
|
|
100
|
+
table.size,
|
|
101
|
+
),
|
|
102
|
+
index("storage_object_status_expires_idx").on(
|
|
103
|
+
table.status,
|
|
104
|
+
table.expiresAt,
|
|
105
|
+
),
|
|
106
|
+
],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
/** The `storage_folder` table: one row per folder, so empty folders list. */
|
|
110
|
+
export const storageFolder = sqliteTable(
|
|
111
|
+
"storage_folder",
|
|
112
|
+
{
|
|
113
|
+
id: id(),
|
|
114
|
+
scope: text("scope").notNull(),
|
|
115
|
+
/** `""` is the root. */
|
|
116
|
+
parentId: text("parent_id").notNull().default(""),
|
|
117
|
+
name: text("name").notNull(),
|
|
118
|
+
path: text("path").notNull(),
|
|
119
|
+
createdAt: timestampNow("created_at"),
|
|
120
|
+
updatedAt: timestampNow("updated_at"),
|
|
121
|
+
},
|
|
122
|
+
(table) => [
|
|
123
|
+
uniqueIndex("storage_folder_scope_path_uk").on(table.scope, table.path),
|
|
124
|
+
uniqueIndex("storage_folder_scope_parent_name_uk").on(
|
|
125
|
+
table.scope,
|
|
126
|
+
table.parentId,
|
|
127
|
+
table.name,
|
|
128
|
+
),
|
|
129
|
+
],
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The FumaDB settings table. The Drizzle adapter reads the schema version
|
|
134
|
+
* from the default of its `version` column, which is stored as `value`.
|
|
135
|
+
*/
|
|
136
|
+
export const dimahS3Settings = sqliteTable("private_dimah_s3_settings", {
|
|
137
|
+
key: text("key").primaryKey(),
|
|
138
|
+
version: text("value").notNull().default(SCHEMA_VERSION),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Every @dimah-s3/db table. Spread it into your Drizzle schema and keep its
|
|
143
|
+
* keys, because the FumaDB Drizzle adapter finds tables by them:
|
|
144
|
+
* `drizzle({ client, relations: defineRelations({ ...dimahS3Tables }) })`.
|
|
145
|
+
*/
|
|
146
|
+
export const dimahS3Tables = {
|
|
147
|
+
storageObject,
|
|
148
|
+
storageFolder,
|
|
149
|
+
private_dimah_s3_settings: dimahS3Settings,
|
|
150
|
+
};
|
package/dist/schema/v1.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare const v1: import("fumadb/schema").Schema<"1.0.0", {
|
|
2
|
-
storageObject: import("fumadb/schema").Table<{
|
|
3
|
-
id: import("fumadb/schema").IdColumn<"varchar(255)", string | null, string>;
|
|
4
|
-
scope: import("fumadb/schema").Column<"string", string, string>;
|
|
5
|
-
bucket: import("fumadb/schema").Column<"string", string, string>;
|
|
6
|
-
key: import("fumadb/schema").Column<"string", string, string>;
|
|
7
|
-
route: import("fumadb/schema").Column<"string", string, string>;
|
|
8
|
-
contentType: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
9
|
-
size: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
|
|
10
|
-
eTag: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
11
|
-
filename: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
12
|
-
status: import("fumadb/schema").Column<"string", string, string>;
|
|
13
|
-
s3Metadata: import("fumadb/schema").Column<"json", unknown, unknown>;
|
|
14
|
-
acl: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
15
|
-
uploadId: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
16
|
-
declaredSize: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
|
|
17
|
-
confirmedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
|
|
18
|
-
expiresAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
|
|
19
|
-
createdAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
|
|
20
|
-
updatedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
|
|
21
|
-
deletedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
|
|
22
|
-
}, {}>;
|
|
23
|
-
}>;
|
|
24
|
-
//# sourceMappingURL=v1.d.ts.map
|
package/dist/schema/v1.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"v1.d.ts","sourceRoot":"","sources":["../../src/schema/v1.ts"],"names":[],"mappings":"AAgCA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;EAKb,CAAC"}
|
package/dist/schema/v2.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../../src/schema/v2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAuE7E,wDAAwD;AACxD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,WAAW,EA+B3C,CAAC;AAyCF;;;GAGG;AACH,eAAO,MAAM,EAAE;;;QArIb,mDAAmD;;;;QAInD,oDAAoD;;QAEpD,+CAA+C;;;;QAI/C,qDAAqD;;QAErD,8EAA8E;;;;QAI9E,+CAA+C;;QAE/C,qEAAqE;;;QAGrE,oDAAoD;;QAEpD,iFAAiF;;QAEjF,sEAAsE;;;;;;;;;;QAYtE,wBAAwB;;QAExB,yDAAyD;;QAEzD,8BAA8B;;;;EAqG9B,CAAC"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
-- @dimah-s3/db schema 1.0.0 → 2.0.0 for MySQL 8.
|
|
2
|
-
-- Back up the database first. MySQL commits each ALTER TABLE on its own, so
|
|
3
|
-
-- a failed step leaves the earlier ones applied.
|
|
4
|
-
-- - `metadata` moves to `s3_metadata`; `attributes`, `folder`, and
|
|
5
|
-
-- `upload_token` start empty (`folder` NULL is the root).
|
|
6
|
-
-- - A missing `filename` becomes the last segment of the key.
|
|
7
|
-
-- - Columns take the 2.0.0 types (see ../../mysql.sql). Timestamps become
|
|
8
|
-
-- datetime(3), converted in the session time zone: run this with the time
|
|
9
|
-
-- zone your app connects with.
|
|
10
|
-
--
|
|
11
|
-
-- If you added the 1.x recommended indexes, drop them first:
|
|
12
|
-
-- DROP INDEX `storage_object_scope_status_created_idx` ON `storage_object`;
|
|
13
|
-
-- DROP INDEX `storage_object_scope_route_idx` ON `storage_object`;
|
|
14
|
-
-- DROP INDEX `storage_object_status_created_idx` ON `storage_object`;
|
|
15
|
-
-- DROP INDEX `storage_object_status_expires_idx` ON `storage_object`;
|
|
16
|
-
|
|
17
|
-
UPDATE `storage_object`
|
|
18
|
-
SET `filename` = COALESCE(NULLIF(SUBSTRING_INDEX(`key`, '/', -1), ''), `key`)
|
|
19
|
-
WHERE `filename` IS NULL;
|
|
20
|
-
UPDATE `storage_object` SET `filename` = LEFT(`filename`, 255);
|
|
21
|
-
|
|
22
|
-
DROP INDEX `storage_object_bucket_key_uk` ON `storage_object`;
|
|
23
|
-
|
|
24
|
-
ALTER TABLE `storage_object`
|
|
25
|
-
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
|
|
26
|
-
|
|
27
|
-
ALTER TABLE `storage_object`
|
|
28
|
-
CHANGE `metadata` `s3_metadata` json,
|
|
29
|
-
ADD COLUMN `folder` varchar(1024),
|
|
30
|
-
ADD COLUMN `attributes` json,
|
|
31
|
-
ADD COLUMN `upload_token` varchar(64),
|
|
32
|
-
MODIFY `id` varchar(255) NOT NULL,
|
|
33
|
-
MODIFY `scope` varchar(255) NOT NULL,
|
|
34
|
-
MODIFY `bucket` varchar(255) NOT NULL,
|
|
35
|
-
MODIFY `key` varchar(1024) NOT NULL,
|
|
36
|
-
MODIFY `route` varchar(255) NOT NULL,
|
|
37
|
-
MODIFY `filename` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
|
|
38
|
-
MODIFY `content_type` varchar(255),
|
|
39
|
-
MODIFY `size` bigint,
|
|
40
|
-
MODIFY `declared_size` bigint,
|
|
41
|
-
MODIFY `e_tag` varchar(255),
|
|
42
|
-
MODIFY `status` varchar(16) NOT NULL,
|
|
43
|
-
MODIFY `acl` varchar(255),
|
|
44
|
-
MODIFY `upload_id` text,
|
|
45
|
-
MODIFY `expires_at` datetime(3),
|
|
46
|
-
MODIFY `confirmed_at` datetime(3),
|
|
47
|
-
MODIFY `created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
48
|
-
MODIFY `updated_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
49
|
-
MODIFY `deleted_at` datetime(3),
|
|
50
|
-
ADD UNIQUE KEY `storage_object_bucket_key_uk` (`bucket`, `key`(512)),
|
|
51
|
-
ADD KEY `storage_object_scope_folder_idx` (`scope`, `status`, `folder`(255), `created_at`),
|
|
52
|
-
ADD KEY `storage_object_scope_updated_idx` (`scope`, `status`, `updated_at`),
|
|
53
|
-
ADD KEY `storage_object_scope_filename_idx` (`scope`, `status`, `filename`),
|
|
54
|
-
ADD KEY `storage_object_scope_size_idx` (`scope`, `status`, `size`),
|
|
55
|
-
ADD KEY `storage_object_status_expires_idx` (`status`, `expires_at`);
|
|
56
|
-
|
|
57
|
-
CREATE TABLE `storage_folder` (
|
|
58
|
-
`id` varchar(255) NOT NULL,
|
|
59
|
-
`scope` varchar(255) NOT NULL,
|
|
60
|
-
`path` varchar(1024) NOT NULL,
|
|
61
|
-
`parent` varchar(1024),
|
|
62
|
-
`name` varchar(255) NOT NULL,
|
|
63
|
-
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
64
|
-
PRIMARY KEY (`id`),
|
|
65
|
-
UNIQUE KEY `storage_folder_scope_path_uk` (`scope`, `path`(512)),
|
|
66
|
-
KEY `storage_folder_scope_parent_idx` (`scope`, `parent`(512))
|
|
67
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
|
68
|
-
|
|
69
|
-
-- Kysely and Prisma read the version from this table. A Drizzle setup reads
|
|
70
|
-
-- it from the table definition instead: skip this statement there.
|
|
71
|
-
UPDATE `private_dimah_s3_settings` SET `value` = '2.0.0' WHERE `key` = 'version';
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
-- @dimah-s3/db schema 1.0.0 → 2.0.0 for PostgreSQL.
|
|
2
|
-
-- Back up the database first.
|
|
3
|
-
-- - `metadata` moves to `s3_metadata`; `attributes`, `folder`, and
|
|
4
|
-
-- `upload_token` start empty (`folder` NULL is the root).
|
|
5
|
-
-- - A missing `filename` becomes the last segment of the key.
|
|
6
|
-
-- - The 1.x recommended indexes give way to the 2.0.0 indexes.
|
|
7
|
-
|
|
8
|
-
BEGIN;
|
|
9
|
-
|
|
10
|
-
ALTER TABLE "storage_object" RENAME COLUMN "metadata" TO "s3_metadata";
|
|
11
|
-
ALTER TABLE "storage_object"
|
|
12
|
-
ADD COLUMN "folder" text,
|
|
13
|
-
ADD COLUMN "attributes" json,
|
|
14
|
-
ADD COLUMN "upload_token" text;
|
|
15
|
-
|
|
16
|
-
UPDATE "storage_object"
|
|
17
|
-
SET "filename" = COALESCE(NULLIF(substring("key" from '[^/]*$'), ''), "key")
|
|
18
|
-
WHERE "filename" IS NULL;
|
|
19
|
-
ALTER TABLE "storage_object" ALTER COLUMN "filename" SET NOT NULL;
|
|
20
|
-
|
|
21
|
-
DROP INDEX IF EXISTS "storage_object_scope_status_created_idx";
|
|
22
|
-
DROP INDEX IF EXISTS "storage_object_scope_route_idx";
|
|
23
|
-
DROP INDEX IF EXISTS "storage_object_status_created_idx";
|
|
24
|
-
|
|
25
|
-
CREATE INDEX IF NOT EXISTS "storage_object_scope_folder_idx" ON "storage_object" ("scope", "status", "folder", "created_at");
|
|
26
|
-
CREATE INDEX IF NOT EXISTS "storage_object_scope_updated_idx" ON "storage_object" ("scope", "status", "updated_at");
|
|
27
|
-
CREATE INDEX IF NOT EXISTS "storage_object_scope_filename_idx" ON "storage_object" ("scope", "status", "filename");
|
|
28
|
-
CREATE INDEX IF NOT EXISTS "storage_object_scope_size_idx" ON "storage_object" ("scope", "status", "size");
|
|
29
|
-
CREATE INDEX IF NOT EXISTS "storage_object_status_expires_idx" ON "storage_object" ("status", "expires_at");
|
|
30
|
-
|
|
31
|
-
CREATE TABLE "storage_folder" (
|
|
32
|
-
"id" varchar(255) PRIMARY KEY NOT NULL,
|
|
33
|
-
"scope" text NOT NULL,
|
|
34
|
-
"path" text NOT NULL,
|
|
35
|
-
"parent" text,
|
|
36
|
-
"name" text NOT NULL,
|
|
37
|
-
"created_at" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
38
|
-
CONSTRAINT "storage_folder_scope_path_uk" UNIQUE ("scope", "path")
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
CREATE INDEX "storage_folder_scope_parent_idx" ON "storage_folder" ("scope", "parent");
|
|
42
|
-
|
|
43
|
-
COMMIT;
|
|
44
|
-
|
|
45
|
-
-- Kysely and Prisma read the version from this table. A Drizzle setup reads
|
|
46
|
-
-- it from the table definition instead: skip this statement there.
|
|
47
|
-
UPDATE "private_dimah_s3_settings" SET "value" = '2.0.0' WHERE "key" = 'version';
|