@dimah-s3/db 2.0.0-beta.0 → 2.0.0-beta.1
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 +31 -88
- package/dist/cli.js.map +1 -1
- package/dist/drizzle/mysql.d.ts +2 -1
- package/dist/drizzle/mysql.d.ts.map +1 -1
- package/dist/drizzle/mysql.js +5 -11
- package/dist/drizzle/mysql.js.map +1 -1
- package/dist/drizzle/pg.d.ts +2 -1
- package/dist/drizzle/pg.d.ts.map +1 -1
- package/dist/drizzle/pg.js +5 -11
- package/dist/drizzle/pg.js.map +1 -1
- package/dist/drizzle/shared.d.ts +3 -12
- package/dist/drizzle/shared.d.ts.map +1 -1
- package/dist/drizzle/sqlite.d.ts +2 -1
- package/dist/drizzle/sqlite.d.ts.map +1 -1
- package/dist/drizzle/sqlite.js +5 -11
- package/dist/drizzle/sqlite.js.map +1 -1
- package/dist/fuma-db.d.ts +5 -26
- 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 +25 -61
- package/dist/index.js.map +1 -1
- package/dist/schema/{v2.d.ts → schema.d.ts} +16 -7
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/store/create-db-store.d.ts +2 -2
- package/dist/store/map-row.d.ts +1 -1
- package/dist/store/object-store.d.ts +4 -4
- package/dist/store/object-store.d.ts.map +1 -1
- package/dist/store/schema-version.d.ts +1 -1
- package/package.json +9 -6
- package/src/drizzle/mysql.ts +172 -0
- package/src/drizzle/pg.ts +140 -0
- package/src/drizzle/sqlite.ts +144 -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
package/README.md
CHANGED
|
@@ -18,12 +18,12 @@ You do not install `fumadb`: the adapters ship from `@dimah-s3/db/adapters/*`.
|
|
|
18
18
|
|
|
19
19
|
Create the schema with one of:
|
|
20
20
|
|
|
21
|
-
- Drizzle: add `dimahS3Tables` from `@dimah-s3/db/drizzle/{sqlite,pg,mysql}`
|
|
21
|
+
- Drizzle: copy `src/drizzle/{sqlite,pg,mysql}.ts` from the package into your schema so you can add columns. Or import `dimahS3Tables` from `@dimah-s3/db/drizzle/{sqlite,pg,mysql}` when the tables stay as they are.
|
|
22
22
|
- Prisma: copy [`prisma/dimah-s3.prisma`](./prisma/dimah-s3.prisma) into your schema.
|
|
23
23
|
- Plain SQL: run [`sql/<dialect>.sql`](./sql).
|
|
24
|
-
- Kysely: call `migrate(client)` from `@dimah-s3/db/cli`. It
|
|
24
|
+
- Kysely: call `migrate(client)` from `@dimah-s3/db/cli`. It creates the tables and the indexes. The FumaDB CLI from `runCli` does the same only with `migrate:up`; its `migrate` command jumps straight to the latest schema and skips the indexes.
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
The package reads schema `2.0.0` and does not upgrade a 1.x database: create the tables on a new database. A database at another schema version throws on the first query. Call `s3.db.checkSchema()` at startup to fail fast.
|
|
27
27
|
|
|
28
28
|
## Server
|
|
29
29
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The FumaDB Drizzle adapter. Pass a Drizzle instance whose schema includes
|
|
3
|
-
*
|
|
3
|
+
* the tables from `src/drizzle/<dialect>.ts`, copied into the app or
|
|
4
|
+
* imported as `dimahS3Tables` from `@dimah-s3/db/drizzle/<dialect>`:
|
|
4
5
|
* `DimahS3DB.client(drizzleAdapter({ db, provider: "postgresql" }))`.
|
|
5
6
|
*/
|
|
6
7
|
export { drizzleAdapter, type DrizzleConfig } from "fumadb/adapters/drizzle";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type DimahS3DbClient } from "./fuma-db";
|
|
2
2
|
/**
|
|
3
3
|
* Runs the interactive FumaDB CLI: generate the ORM schema, or migrate when
|
|
4
|
-
* the client uses the Kysely adapter. Prefer {@link migrate}
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* the client uses the Kysely adapter. Prefer {@link migrate}. Only
|
|
5
|
+
* `migrate:up`, one version at a time, runs the steps the schema needs,
|
|
6
|
+
* including the indexes. The CLI `migrate` command jumps to the latest
|
|
7
|
+
* schema and skips them.
|
|
7
8
|
*
|
|
8
9
|
* ```ts
|
|
9
10
|
* // scripts/db.ts
|
|
@@ -15,12 +16,10 @@ import { type DimahS3DbClient } from "./fuma-db";
|
|
|
15
16
|
*/
|
|
16
17
|
export declare function runCli(client: DimahS3DbClient): Promise<void>;
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* `sql/upgrade/1.0.0-2.0.0/sqlite.sql`. It needs the Kysely adapter; with
|
|
23
|
-
* Drizzle or Prisma, use your ORM's migrations or the files in `sql/`.
|
|
19
|
+
* Creates the schema this package reads, one version at a time, so the
|
|
20
|
+
* schema's own steps run (the indexes among them). It needs the Kysely
|
|
21
|
+
* adapter; with Drizzle or Prisma, use your ORM's migrations or the files
|
|
22
|
+
* in `sql/`. It does not upgrade a database at another version.
|
|
24
23
|
*
|
|
25
24
|
* ```ts
|
|
26
25
|
* import { DimahS3DB } from "@dimah-s3/db";
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAYpE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBpE"}
|
package/dist/cli.js
CHANGED
|
@@ -3,37 +3,10 @@ import { fumadb } from 'fumadb';
|
|
|
3
3
|
import { table, column, idColumn, schema } from 'fumadb/schema';
|
|
4
4
|
|
|
5
5
|
// src/cli.ts
|
|
6
|
-
var storageObject = table("storage_object", {
|
|
7
|
-
id: idColumn("id", "varchar(255)").defaultTo$("auto"),
|
|
8
|
-
scope: column("scope", "string"),
|
|
9
|
-
bucket: column("bucket", "string"),
|
|
10
|
-
key: column("key", "string"),
|
|
11
|
-
route: column("route", "string"),
|
|
12
|
-
contentType: column("content_type", "string").nullable(),
|
|
13
|
-
size: column("size", "bigint").nullable(),
|
|
14
|
-
eTag: column("e_tag", "string").nullable(),
|
|
15
|
-
filename: column("filename", "string").nullable(),
|
|
16
|
-
status: column("status", "string"),
|
|
17
|
-
s3Metadata: column("metadata", "json").nullable(),
|
|
18
|
-
acl: column("acl", "string").nullable(),
|
|
19
|
-
uploadId: column("upload_id", "string").nullable(),
|
|
20
|
-
declaredSize: column("declared_size", "bigint").nullable(),
|
|
21
|
-
confirmedAt: column("confirmed_at", "timestamp").nullable(),
|
|
22
|
-
expiresAt: column("expires_at", "timestamp").nullable(),
|
|
23
|
-
createdAt: column("created_at", "timestamp").defaultTo$("now"),
|
|
24
|
-
updatedAt: column("updated_at", "timestamp").defaultTo$("now"),
|
|
25
|
-
deletedAt: column("deleted_at", "timestamp").nullable()
|
|
26
|
-
}).unique("storage_object_bucket_key_uk", ["bucket", "key"]);
|
|
27
|
-
var v1 = schema({
|
|
28
|
-
version: "1.0.0",
|
|
29
|
-
tables: {
|
|
30
|
-
storageObject
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
6
|
function byteCount(name) {
|
|
34
7
|
return column(name, "bigint").nullable();
|
|
35
8
|
}
|
|
36
|
-
var
|
|
9
|
+
var storageObject = table("storage_object", {
|
|
37
10
|
id: idColumn("id", "varchar(255)").defaultTo$("auto"),
|
|
38
11
|
/** Owner, for example `user:123` or `org:acme`. */
|
|
39
12
|
scope: column("scope", "string"),
|
|
@@ -78,7 +51,7 @@ var storageFolder = table("storage_folder", {
|
|
|
78
51
|
name: column("name", "string"),
|
|
79
52
|
createdAt: column("created_at", "timestamp").defaultTo$("now")
|
|
80
53
|
}).unique("storage_folder_scope_path_uk", ["scope", "path"]);
|
|
81
|
-
var
|
|
54
|
+
var schemaIndexes = [
|
|
82
55
|
{
|
|
83
56
|
name: "storage_object_scope_folder_idx",
|
|
84
57
|
table: "storage_object",
|
|
@@ -110,92 +83,62 @@ var v2Indexes = [
|
|
|
110
83
|
columns: ["scope", "parent"]
|
|
111
84
|
}
|
|
112
85
|
];
|
|
113
|
-
var v1Indexes = [
|
|
114
|
-
"storage_object_scope_status_created_idx",
|
|
115
|
-
"storage_object_scope_route_idx",
|
|
116
|
-
"storage_object_status_created_idx"
|
|
117
|
-
];
|
|
118
86
|
var custom = (sql) => ({ type: "custom", sql });
|
|
119
|
-
var
|
|
120
|
-
var
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
var afterV2 = [
|
|
126
|
-
...v1Indexes.map((name) => custom(`DROP INDEX IF EXISTS "${name}"`)),
|
|
127
|
-
...v2Indexes.map((index) => {
|
|
128
|
-
const columns = index.columns.map((name) => `"${name}"`).join(", ");
|
|
129
|
-
return custom(
|
|
130
|
-
`CREATE INDEX IF NOT EXISTS "${index.name}" ON "${index.table}" (${columns})`
|
|
131
|
-
);
|
|
132
|
-
})
|
|
133
|
-
];
|
|
134
|
-
var v2 = schema({
|
|
87
|
+
var PREDECESSOR_VERSION = "0.0.1";
|
|
88
|
+
var predecessor = schema({
|
|
89
|
+
version: PREDECESSOR_VERSION,
|
|
90
|
+
tables: {}
|
|
91
|
+
});
|
|
92
|
+
var dbSchema = schema({
|
|
135
93
|
version: "2.0.0",
|
|
136
94
|
tables: {
|
|
137
|
-
storageObject
|
|
95
|
+
storageObject,
|
|
138
96
|
storageFolder
|
|
139
97
|
},
|
|
140
98
|
async up({ auto }) {
|
|
141
|
-
|
|
99
|
+
const indexes = schemaIndexes.map((index) => {
|
|
100
|
+
const columns = index.columns.map((name) => `"${name}"`).join(", ");
|
|
101
|
+
return custom(
|
|
102
|
+
`CREATE INDEX IF NOT EXISTS "${index.name}" ON "${index.table}" (${columns})`
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
return [...await auto(), ...indexes];
|
|
142
106
|
}
|
|
143
107
|
});
|
|
144
108
|
|
|
145
109
|
// src/fuma-db.ts
|
|
146
110
|
fumadb({
|
|
147
111
|
namespace: "dimah_s3",
|
|
148
|
-
schemas: [
|
|
112
|
+
schemas: [predecessor, dbSchema]
|
|
149
113
|
});
|
|
150
|
-
var DB_SCHEMA_VERSION =
|
|
114
|
+
var DB_SCHEMA_VERSION = dbSchema.version;
|
|
151
115
|
|
|
152
116
|
// src/cli.ts
|
|
153
|
-
var
|
|
117
|
+
var RESUMABLE = /* @__PURE__ */ new Set([PREDECESSOR_VERSION, DB_SCHEMA_VERSION]);
|
|
154
118
|
function runCli(client) {
|
|
155
119
|
const { main } = createCli({
|
|
156
120
|
db: client,
|
|
157
121
|
command: "dimah-s3-db",
|
|
158
122
|
description: "FumaDB CLI for @dimah-s3/db",
|
|
159
|
-
version: "2.0.0-beta.
|
|
123
|
+
version: "2.0.0-beta.1"
|
|
160
124
|
});
|
|
161
125
|
return main();
|
|
162
126
|
}
|
|
163
127
|
async function migrate(client) {
|
|
128
|
+
let version;
|
|
129
|
+
try {
|
|
130
|
+
version = await client.version();
|
|
131
|
+
} catch {
|
|
132
|
+
version = void 0;
|
|
133
|
+
}
|
|
134
|
+
if (version !== void 0 && !RESUMABLE.has(version)) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`[dimah-s3/db] The database is at schema ${version}, which this package does not upgrade. Create schema ${DB_SCHEMA_VERSION} on a new database.`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
164
139
|
const migrator = client.createMigrator();
|
|
165
140
|
for (let next = await migrator.next(); next; next = await migrator.next()) {
|
|
166
|
-
const from = await migrator.getVersion();
|
|
167
141
|
await (await migrator.up()).execute();
|
|
168
|
-
if (from === v1.version) await rewriteSizes(client);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
async function rewriteSizes(client) {
|
|
172
|
-
const orm = client.orm(DB_SCHEMA_VERSION);
|
|
173
|
-
const toNumber = (value) => value === null ? null : Number(value);
|
|
174
|
-
let after;
|
|
175
|
-
for (; ; ) {
|
|
176
|
-
const rows = await orm.findMany("storageObject", {
|
|
177
|
-
select: ["id", "size", "declaredSize"],
|
|
178
|
-
where: (b) => b.and(
|
|
179
|
-
b.or(b.isNotNull("size"), b.isNotNull("declaredSize")),
|
|
180
|
-
after === void 0 || b("id", ">", after)
|
|
181
|
-
),
|
|
182
|
-
orderBy: [["id", "asc"]],
|
|
183
|
-
limit: MIGRATE_BATCH
|
|
184
|
-
});
|
|
185
|
-
for (const row of rows) {
|
|
186
|
-
if (typeof row.size !== "bigint" && typeof row.declaredSize !== "bigint") {
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
await orm.updateMany("storageObject", {
|
|
190
|
-
where: (b) => b("id", "=", row.id),
|
|
191
|
-
set: {
|
|
192
|
-
size: toNumber(row.size),
|
|
193
|
-
declaredSize: toNumber(row.declaredSize)
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
if (rows.length < MIGRATE_BATCH) return;
|
|
198
|
-
after = rows.at(-1)?.id;
|
|
199
142
|
}
|
|
200
143
|
}
|
|
201
144
|
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema/v1.ts","../src/schema/v2.ts","../src/fuma-db.ts","../src/cli.ts"],"names":["column","storageObject","table","idColumn","schema"],"mappings":";;;;;AAUA,IAAM,aAAA,GAAgB,MAAM,gBAAA,EAAkB;AAAA,EAC5C,IAAI,QAAA,CAAS,IAAA,EAAM,cAAc,CAAA,CAAE,WAAW,MAAM,CAAA;AAAA,EACpD,KAAA,EAAO,MAAA,CAAO,OAAA,EAAS,QAAQ,CAAA;AAAA,EAC/B,MAAA,EAAQ,MAAA,CAAO,QAAA,EAAU,QAAQ,CAAA;AAAA,EACjC,GAAA,EAAK,MAAA,CAAO,KAAA,EAAO,QAAQ,CAAA;AAAA,EAC3B,KAAA,EAAO,MAAA,CAAO,OAAA,EAAS,QAAQ,CAAA;AAAA,EAC/B,WAAA,EAAa,MAAA,CAAO,cAAA,EAAgB,QAAQ,EAAE,QAAA,EAAS;AAAA,EACvD,IAAA,EAAM,MAAA,CAAO,MAAA,EAAQ,QAAQ,EAAE,QAAA,EAAS;AAAA,EACxC,IAAA,EAAM,MAAA,CAAO,OAAA,EAAS,QAAQ,EAAE,QAAA,EAAS;AAAA,EACzC,QAAA,EAAU,MAAA,CAAO,UAAA,EAAY,QAAQ,EAAE,QAAA,EAAS;AAAA,EAChD,MAAA,EAAQ,MAAA,CAAO,QAAA,EAAU,QAAQ,CAAA;AAAA,EAC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,IAAA,CAAK,SAAS,aAAA,EAAe;AACjC,IAAA,KAAA,GAAQ,IAAA,CAAK,EAAA,CAAG,EAAE,CAAA,EAAG,EAAA;AAAA,EACvB;AACF","file":"cli.js","sourcesContent":["import { column, idColumn, schema, table } from \"fumadb/schema\";\n\n/**\n * Schema 1.0.0, kept so the FumaDB migrator can move a 1.x database to\n * 2.0.0 (`v2.ts`). Nothing queries it.\n *\n * The `metadata` column has the ORM name `s3Metadata`, the name it has in\n * 2.0.0, so the migrator renames the column (and SQLite's table rebuild\n * copies it) instead of dropping its data.\n */\nconst storageObject = table(\"storage_object\", {\n id: idColumn(\"id\", \"varchar(255)\").defaultTo$(\"auto\"),\n scope: column(\"scope\", \"string\"),\n bucket: column(\"bucket\", \"string\"),\n key: column(\"key\", \"string\"),\n route: column(\"route\", \"string\"),\n contentType: column(\"content_type\", \"string\").nullable(),\n size: column(\"size\", \"bigint\").nullable(),\n eTag: column(\"e_tag\", \"string\").nullable(),\n filename: column(\"filename\", \"string\").nullable(),\n status: column(\"status\", \"string\"),\n s3Metadata: column(\"metadata\", \"json\").nullable(),\n acl: column(\"acl\", \"string\").nullable(),\n uploadId: column(\"upload_id\", \"string\").nullable(),\n declaredSize: column(\"declared_size\", \"bigint\").nullable(),\n confirmedAt: column(\"confirmed_at\", \"timestamp\").nullable(),\n expiresAt: column(\"expires_at\", \"timestamp\").nullable(),\n createdAt: column(\"created_at\", \"timestamp\").defaultTo$(\"now\"),\n updatedAt: column(\"updated_at\", \"timestamp\").defaultTo$(\"now\"),\n deletedAt: column(\"deleted_at\", \"timestamp\").nullable(),\n}).unique(\"storage_object_bucket_key_uk\", [\"bucket\", \"key\"]);\n\nexport const v1 = schema({\n version: \"1.0.0\",\n tables: {\n storageObject,\n },\n});\n","import { column, idColumn, schema, table, type Column } from \"fumadb/schema\";\n\n/**\n * A byte count. The column is a `bigint` (int8 on PostgreSQL and MySQL), but\n * values are bound as numbers so SQLite stores a number instead of FumaDB's\n * 8-byte blob, which would sort after every number: INTEGER in the shipped\n * SQL, or REAL in a column FumaDB created, compared by value either way.\n * Drivers read int8 back as a number, a bigint, or a string, and a 1.x\n * SQLite row not yet migrated still holds a blob (read as a bigint).\n */\nfunction byteCount(name: string) {\n return column(name, \"bigint\").nullable() as unknown as Column<\n \"bigint\",\n number | null,\n number | bigint | string | null\n >;\n}\n\n/**\n * One row per tracked object:\n * `pending` (presigned) → `active` (confirmed) → `deleted` (soft delete).\n * `purging` marks a stale pending row that purge has claimed.\n */\nconst storageObject = table(\"storage_object\", {\n id: idColumn(\"id\", \"varchar(255)\").defaultTo$(\"auto\"),\n /** Owner, for example `user:123` or `org:acme`. */\n scope: column(\"scope\", \"string\"),\n bucket: column(\"bucket\", \"string\"),\n key: column(\"key\", \"string\"),\n /** Named dimah-s3 route that created the object. */\n route: column(\"route\", \"string\"),\n /** Logical folder path. `null` is the root. */\n folder: column(\"folder\", \"string\").nullable(),\n filename: column(\"filename\", \"string\"),\n contentType: column(\"content_type\", \"string\").nullable(),\n /** Verified size from HeadObject, set on confirm. */\n size: byteCount(\"size\"),\n /** Size the client declared before confirm. Quota counts it while pending. */\n declaredSize: byteCount(\"declared_size\"),\n eTag: column(\"e_tag\", \"string\").nullable(),\n status: column(\"status\", \"string\"),\n /** S3 user metadata of the verified object. */\n s3Metadata: column(\"s3_metadata\", \"json\").nullable(),\n /** App attributes, validated by the plugin's `attributes.schema`. */\n attributes: column(\"attributes\", \"json\").nullable(),\n acl: column(\"acl\", \"string\").nullable(),\n /** Multipart upload ID while the row is pending. */\n uploadId: column(\"upload_id\", \"string\").nullable(),\n /** Token of the upload ticket that wrote the row. Confirm and purge match it. */\n uploadToken: column(\"upload_token\", \"string\").nullable(),\n /** Confirm deadline of a pending row (the upload ticket's expiry). */\n expiresAt: column(\"expires_at\", \"timestamp\").nullable(),\n confirmedAt: column(\"confirmed_at\", \"timestamp\").nullable(),\n createdAt: column(\"created_at\", \"timestamp\").defaultTo$(\"now\"),\n updatedAt: column(\"updated_at\", \"timestamp\").defaultTo$(\"now\"),\n deletedAt: column(\"deleted_at\", \"timestamp\").nullable(),\n}).unique(\"storage_object_bucket_key_uk\", [\"bucket\", \"key\"]);\n\n/** One row per folder, so an empty folder still lists. */\nconst storageFolder = table(\"storage_folder\", {\n id: idColumn(\"id\", \"varchar(255)\").defaultTo$(\"auto\"),\n scope: column(\"scope\", \"string\"),\n /** Full folder path. */\n path: column(\"path\", \"string\"),\n /** Path of the containing folder. `null` is the root. */\n parent: column(\"parent\", \"string\").nullable(),\n /** Last segment of `path`. */\n name: column(\"name\", \"string\"),\n createdAt: column(\"created_at\", \"timestamp\").defaultTo$(\"now\"),\n}).unique(\"storage_folder_scope_path_uk\", [\"scope\", \"path\"]);\n\n/** A secondary index, by SQL table and column names. */\nexport type SchemaIndex = {\n name: string;\n table: \"storage_object\" | \"storage_folder\";\n columns: readonly string[];\n};\n\n/**\n * Secondary indexes of schema 2.0.0. FumaDB cannot declare them, so the SQL\n * files, the Drizzle tables, and the Prisma schema carry them.\n */\nexport const v2Indexes: readonly SchemaIndex[] = [\n {\n name: \"storage_object_scope_folder_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"folder\", \"created_at\"],\n },\n {\n name: \"storage_object_scope_updated_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"updated_at\"],\n },\n {\n name: \"storage_object_scope_filename_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"filename\"],\n },\n {\n name: \"storage_object_scope_size_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"size\"],\n },\n {\n name: \"storage_object_status_expires_idx\",\n table: \"storage_object\",\n columns: [\"status\", \"expires_at\"],\n },\n {\n name: \"storage_folder_scope_parent_idx\",\n table: \"storage_folder\",\n columns: [\"scope\", \"parent\"],\n },\n];\n\n/** The secondary indexes 1.x recommended that 2.0.0 replaces. */\nconst v1Indexes = [\n \"storage_object_scope_status_created_idx\",\n \"storage_object_scope_route_idx\",\n \"storage_object_status_created_idx\",\n];\n\nconst custom = (sql: string) => ({ type: \"custom\" as const, sql });\n\n/**\n * The last segment of `key`, or the whole key when it ends in `/`, in syntax\n * SQLite and PostgreSQL share. Trimming every character but `/` from the\n * right leaves the key up to its last `/`.\n */\nconst keyName = `COALESCE(NULLIF(substr(\"key\", length(rtrim(\"key\", replace(\"key\", '/', ''))) + 1), ''), \"key\")`;\n\n/**\n * Runs before the statements FumaDB generates for 1.0.0 → 2.0.0, in syntax\n * SQLite and PostgreSQL share. `filename` becomes required, so a missing one\n * is filled from the key the way `sql/upgrade/1.0.0-2.0.0/<dialect>.sql`\n * does. `migrate()` converts 1.x SQLite blob sizes afterwards.\n */\nconst beforeV2 = [\n custom(\n `UPDATE \"storage_object\" SET \"filename\" = ${keyName} WHERE \"filename\" IS NULL`,\n ),\n];\n\n/** Runs after them: the 1.x recommended indexes give way to {@link v2Indexes}. */\nconst afterV2 = [\n ...v1Indexes.map((name) => custom(`DROP INDEX IF EXISTS \"${name}\"`)),\n ...v2Indexes.map((index) => {\n const columns = index.columns.map((name) => `\"${name}\"`).join(\", \");\n return custom(\n `CREATE INDEX IF NOT EXISTS \"${index.name}\" ON \"${index.table}\" (${columns})`,\n );\n }),\n];\n\n/**\n * Schema 2.0.0: logical folders (`folder` plus `storage_folder`), S3 metadata\n * split from typed `attributes`, the upload token, and the sort indexes.\n */\nexport const v2 = schema({\n version: \"2.0.0\",\n tables: {\n storageObject,\n storageFolder,\n },\n async up({ auto }) {\n return [...beforeV2, ...(await auto()), ...afterV2];\n },\n});\n","import { fumadb, type InferFumaDB } from \"fumadb\";\nimport { v1 } from \"./schema/v1\";\nimport { v2 } from \"./schema/v2\";\n\n/**\n * The @dimah-s3/db FumaDB library. Call `DimahS3DB.client(adapter)` with an\n * adapter from `@dimah-s3/db/adapters/*` to get a {@link DimahS3DbClient}.\n */\nexport const DimahS3DB = fumadb({\n namespace: \"dimah_s3\",\n schemas: [v1, v2],\n});\n\n/** FumaDB client for the @dimah-s3/db schemas. */\nexport type DimahS3DbClient = InferFumaDB<typeof DimahS3DB>;\n\n/** The schema version the stores read and write. */\nexport const DB_SCHEMA_VERSION = v2.version;\n\nexport { v2 };\n","import { createCli } from \"fumadb/cli\";\nimport { DB_SCHEMA_VERSION, type DimahS3DbClient } from \"./fuma-db\";\nimport { v1 } from \"./schema/v1\";\n\ndeclare const __DIMAH_S3_DB_VERSION__: string;\n\n/** Rows `migrate` rewrites per query. */\nconst MIGRATE_BATCH = 500;\n\n/**\n * Runs the interactive FumaDB CLI: generate the ORM schema, or migrate when\n * the client uses the Kysely adapter. Prefer {@link migrate} to migrate:\n * only `migrate:up`, one version at a time, runs the steps 2.0.0 needs,\n * and no CLI command converts 1.x SQLite sizes.\n *\n * ```ts\n * // scripts/db.ts\n * import { runCli } from \"@dimah-s3/db/cli\";\n * import { dimahS3Db } from \"../lib/s3\";\n *\n * await runCli(dimahS3Db);\n * ```\n */\nexport function runCli(client: DimahS3DbClient): Promise<void> {\n const { main } = createCli({\n db: client,\n command: \"dimah-s3-db\",\n description: \"FumaDB CLI for @dimah-s3/db\",\n version: __DIMAH_S3_DB_VERSION__,\n });\n\n return main();\n}\n\n/**\n * Migrates the database to the schema this version needs, from an empty\n * database or from schema 1.0.0, one version at a time, so each version's\n * own steps run (the 2.0.0 indexes among them). An upgrade from 1.0.0 also\n * turns 1.x SQLite blob sizes into numbers, like\n * `sql/upgrade/1.0.0-2.0.0/sqlite.sql`. It needs the Kysely adapter; with\n * Drizzle or Prisma, use your ORM's migrations or the files in `sql/`.\n *\n * ```ts\n * import { DimahS3DB } from \"@dimah-s3/db\";\n * import { kyselyAdapter } from \"@dimah-s3/db/adapters/kysely\";\n * import { migrate } from \"@dimah-s3/db/cli\";\n *\n * await migrate(DimahS3DB.client(kyselyAdapter({ db: kysely, provider: \"postgresql\" })));\n * ```\n */\nexport async function migrate(client: DimahS3DbClient): Promise<void> {\n const migrator = client.createMigrator();\n for (let next = await migrator.next(); next; next = await migrator.next()) {\n const from = await migrator.getVersion();\n await (await migrator.up()).execute();\n if (from === v1.version) await rewriteSizes(client);\n }\n}\n\n/**\n * Rewrites the sizes 1.x stored as FumaDB bigints. SQLite kept those as\n * 8-byte blobs, which sort after every number. FumaDB reads a blob back as\n * a bigint and stores a number as a number.\n */\nasync function rewriteSizes(client: DimahS3DbClient): Promise<void> {\n const orm = client.orm(DB_SCHEMA_VERSION);\n const toNumber = (value: number | bigint | string | null) =>\n value === null ? null : Number(value);\n let after: string | undefined;\n for (;;) {\n const rows = await orm.findMany(\"storageObject\", {\n select: [\"id\", \"size\", \"declaredSize\"],\n where: (b) =>\n b.and(\n b.or(b.isNotNull(\"size\"), b.isNotNull(\"declaredSize\")),\n after === undefined || b(\"id\", \">\", after),\n ),\n orderBy: [[\"id\", \"asc\"]],\n limit: MIGRATE_BATCH,\n });\n for (const row of rows) {\n if (\n typeof row.size !== \"bigint\" &&\n typeof row.declaredSize !== \"bigint\"\n ) {\n continue;\n }\n await orm.updateMany(\"storageObject\", {\n where: (b) => b(\"id\", \"=\", row.id),\n set: {\n size: toNumber(row.size),\n declaredSize: toNumber(row.declaredSize),\n },\n });\n }\n if (rows.length < MIGRATE_BATCH) return;\n after = rows.at(-1)?.id;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/schema/schema.ts","../src/fuma-db.ts","../src/cli.ts"],"names":[],"mappings":";;;;;AASA,SAAS,UAAU,IAAA,EAAc;AAC/B,EAAA,OAAO,MAAA,CAAO,IAAA,EAAM,QAAQ,CAAA,CAAE,QAAA,EAAS;AAKzC;AAOA,IAAM,aAAA,GAAgB,MAAM,gBAAA,EAAkB;AAAA,EAC5C,IAAI,QAAA,CAAS,IAAA,EAAM,cAAc,CAAA,CAAE,WAAW,MAAM,CAAA;AAAA;AAAA,EAEpD,KAAA,EAAO,MAAA,CAAO,OAAA,EAAS,QAAQ,CAAA;AAAA,EAC/B,MAAA,EAAQ,MAAA,CAAO,QAAA,EAAU,QAAQ,CAAA;AAAA,EACjC,GAAA,EA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column } from \"fumadb/schema\";\n\n/**\n * A byte count. The column is a `bigint` (int8 on PostgreSQL and MySQL), but\n * values are bound as numbers so SQLite stores a number instead of FumaDB's\n * 8-byte blob, which would sort after every number: INTEGER in the shipped\n * SQL, or REAL in a column FumaDB created, compared by value either way.\n * Drivers read int8 back as a number, a bigint, or a string.\n */\nfunction byteCount(name: string) {\n return column(name, \"bigint\").nullable() as unknown as Column<\n \"bigint\",\n number | null,\n number | bigint | string | null\n >;\n}\n\n/**\n * One row per tracked object:\n * `pending` (presigned) → `active` (confirmed) → `deleted` (soft delete).\n * `purging` marks a stale pending row that purge has claimed.\n */\nconst storageObject = table(\"storage_object\", {\n id: idColumn(\"id\", \"varchar(255)\").defaultTo$(\"auto\"),\n /** Owner, for example `user:123` or `org:acme`. */\n scope: column(\"scope\", \"string\"),\n bucket: column(\"bucket\", \"string\"),\n key: column(\"key\", \"string\"),\n /** Named dimah-s3 route that created the object. */\n route: column(\"route\", \"string\"),\n /** Logical folder path. `null` is the root. */\n folder: column(\"folder\", \"string\").nullable(),\n filename: column(\"filename\", \"string\"),\n contentType: column(\"content_type\", \"string\").nullable(),\n /** Verified size from HeadObject, set on confirm. */\n size: byteCount(\"size\"),\n /** Size the client declared before confirm. Quota counts it while pending. */\n declaredSize: byteCount(\"declared_size\"),\n eTag: column(\"e_tag\", \"string\").nullable(),\n status: column(\"status\", \"string\"),\n /** S3 user metadata of the verified object. */\n s3Metadata: column(\"s3_metadata\", \"json\").nullable(),\n /** App attributes, validated by the plugin's `attributes.schema`. */\n attributes: column(\"attributes\", \"json\").nullable(),\n acl: column(\"acl\", \"string\").nullable(),\n /** Multipart upload ID while the row is pending. */\n uploadId: column(\"upload_id\", \"string\").nullable(),\n /** Token of the upload ticket that wrote the row. Confirm and purge match it. */\n uploadToken: column(\"upload_token\", \"string\").nullable(),\n /** Confirm deadline of a pending row (the upload ticket's expiry). */\n expiresAt: column(\"expires_at\", \"timestamp\").nullable(),\n confirmedAt: column(\"confirmed_at\", \"timestamp\").nullable(),\n createdAt: column(\"created_at\", \"timestamp\").defaultTo$(\"now\"),\n updatedAt: column(\"updated_at\", \"timestamp\").defaultTo$(\"now\"),\n deletedAt: column(\"deleted_at\", \"timestamp\").nullable(),\n}).unique(\"storage_object_bucket_key_uk\", [\"bucket\", \"key\"]);\n\n/** One row per folder, so an empty folder still lists. */\nconst storageFolder = table(\"storage_folder\", {\n id: idColumn(\"id\", \"varchar(255)\").defaultTo$(\"auto\"),\n scope: column(\"scope\", \"string\"),\n /** Full folder path. */\n path: column(\"path\", \"string\"),\n /** Path of the containing folder. `null` is the root. */\n parent: column(\"parent\", \"string\").nullable(),\n /** Last segment of `path`. */\n name: column(\"name\", \"string\"),\n createdAt: column(\"created_at\", \"timestamp\").defaultTo$(\"now\"),\n}).unique(\"storage_folder_scope_path_uk\", [\"scope\", \"path\"]);\n\n/** A secondary index, by SQL table and column names. */\nexport type SchemaIndex = {\n name: string;\n table: \"storage_object\" | \"storage_folder\";\n columns: readonly string[];\n};\n\n/**\n * Secondary indexes. FumaDB cannot declare them, so {@link dbSchema}'s\n * migration, the SQL files, the Drizzle tables, and the Prisma schema carry\n * them.\n */\nexport const schemaIndexes: readonly SchemaIndex[] = [\n {\n name: \"storage_object_scope_folder_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"folder\", \"created_at\"],\n },\n {\n name: \"storage_object_scope_updated_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"updated_at\"],\n },\n {\n name: \"storage_object_scope_filename_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"filename\"],\n },\n {\n name: \"storage_object_scope_size_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"size\"],\n },\n {\n name: \"storage_object_status_expires_idx\",\n table: \"storage_object\",\n columns: [\"status\", \"expires_at\"],\n },\n {\n name: \"storage_folder_scope_parent_idx\",\n table: \"storage_folder\",\n columns: [\"scope\", \"parent\"],\n },\n];\n\nconst custom = (sql: string) => ({ type: \"custom\" as const, sql });\n\n/**\n * FumaDB runs `up` only when migrating from the previous entry, and skips\n * `up` on the first one. This empty entry exists so {@link dbSchema} can\n * create the indexes on a new database. A finished database is at\n * {@link dbSchema}.\n */\nexport const PREDECESSOR_VERSION = \"0.0.1\";\n\nexport const predecessor = schema({\n version: PREDECESSOR_VERSION,\n tables: {},\n});\n\n/**\n * The @dimah-s3/db schema, version `2.0.0`. The migration creates the\n * secondary indexes after the tables, because FumaDB cannot declare them.\n */\nexport const dbSchema = schema({\n version: \"2.0.0\",\n tables: {\n storageObject,\n storageFolder,\n },\n async up({ auto }) {\n const indexes = schemaIndexes.map((index) => {\n const columns = index.columns.map((name) => `\"${name}\"`).join(\", \");\n return custom(\n `CREATE INDEX IF NOT EXISTS \"${index.name}\" ON \"${index.table}\" (${columns})`,\n );\n });\n return [...(await auto()), ...indexes];\n },\n});\n","import { fumadb, type InferFumaDB } from \"fumadb\";\nimport { dbSchema, predecessor } from \"./schema/schema\";\n\n/**\n * The @dimah-s3/db FumaDB library. Call `DimahS3DB.client(adapter)` with an\n * adapter from `@dimah-s3/db/adapters/*` to get a {@link DimahS3DbClient}.\n *\n * `predecessor` is empty. FumaDB skips `up` on the first schema, and the\n * indexes are created in {@link dbSchema}'s `up`.\n */\nexport const DimahS3DB = fumadb({\n namespace: \"dimah_s3\",\n schemas: [predecessor, dbSchema],\n});\n\n/** FumaDB client for the @dimah-s3/db schema. */\nexport type DimahS3DbClient = InferFumaDB<typeof DimahS3DB>;\n\n/** The schema version the stores read and write. */\nexport const DB_SCHEMA_VERSION = dbSchema.version;\n","import { createCli } from \"fumadb/cli\";\nimport { DB_SCHEMA_VERSION, type DimahS3DbClient } from \"./fuma-db\";\nimport { PREDECESSOR_VERSION } from \"./schema/schema\";\n\ndeclare const __DIMAH_S3_DB_VERSION__: string;\n\n/**\n * Versions `migrate` may continue from: an empty database, a migration that\n * stopped on the empty predecessor, or a database already at\n * {@link DB_SCHEMA_VERSION}.\n */\nconst RESUMABLE = new Set<string>([PREDECESSOR_VERSION, DB_SCHEMA_VERSION]);\n\n/**\n * Runs the interactive FumaDB CLI: generate the ORM schema, or migrate when\n * the client uses the Kysely adapter. Prefer {@link migrate}. Only\n * `migrate:up`, one version at a time, runs the steps the schema needs,\n * including the indexes. The CLI `migrate` command jumps to the latest\n * schema and skips them.\n *\n * ```ts\n * // scripts/db.ts\n * import { runCli } from \"@dimah-s3/db/cli\";\n * import { dimahS3Db } from \"../lib/s3\";\n *\n * await runCli(dimahS3Db);\n * ```\n */\nexport function runCli(client: DimahS3DbClient): Promise<void> {\n const { main } = createCli({\n db: client,\n command: \"dimah-s3-db\",\n description: \"FumaDB CLI for @dimah-s3/db\",\n version: __DIMAH_S3_DB_VERSION__,\n });\n\n return main();\n}\n\n/**\n * Creates the schema this package reads, one version at a time, so the\n * schema's own steps run (the indexes among them). It needs the Kysely\n * adapter; with Drizzle or Prisma, use your ORM's migrations or the files\n * in `sql/`. It does not upgrade a database at another version.\n *\n * ```ts\n * import { DimahS3DB } from \"@dimah-s3/db\";\n * import { kyselyAdapter } from \"@dimah-s3/db/adapters/kysely\";\n * import { migrate } from \"@dimah-s3/db/cli\";\n *\n * await migrate(DimahS3DB.client(kyselyAdapter({ db: kysely, provider: \"postgresql\" })));\n * ```\n */\nexport async function migrate(client: DimahS3DbClient): Promise<void> {\n let version: string | undefined;\n try {\n version = await client.version();\n } catch {\n version = undefined;\n }\n if (version !== undefined && !RESUMABLE.has(version)) {\n throw new Error(\n `[dimah-s3/db] The database is at schema ${version}, which this package does not upgrade. Create schema ${DB_SCHEMA_VERSION} on a new database.`,\n );\n }\n const migrator = client.createMigrator();\n for (let next = await migrator.next(); next; next = await migrator.next()) {\n await (await migrator.up()).execute();\n }\n}\n"]}
|
package/dist/drizzle/mysql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MySqlColumn } from "drizzle-orm/mysql-core";
|
|
2
|
-
|
|
2
|
+
type StorageObjectStatus = "pending" | "active" | "deleted" | "purging";
|
|
3
3
|
/** The `storage_object` table: one row per tracked object. */
|
|
4
4
|
export declare const storageObject: import("drizzle-orm/mysql-core").MySqlTableWithColumns<{
|
|
5
5
|
name: "storage_object";
|
|
@@ -1021,4 +1021,5 @@ export declare const dimahS3Tables: {
|
|
|
1021
1021
|
isAlias: false;
|
|
1022
1022
|
}>;
|
|
1023
1023
|
};
|
|
1024
|
+
export {};
|
|
1024
1025
|
//# sourceMappingURL=mysql.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/drizzle/mysql.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/drizzle/mysql.ts"],"names":[],"mappings":"AAmBA,OAAO,EASL,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAEhC,KAAK,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAqCxE,8DAA8D;AAC9D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2DzB,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG1B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIzB,CAAC"}
|
package/dist/drizzle/mysql.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
+
import { createId } from '@paralleldrive/cuid2';
|
|
1
2
|
import { sql } from 'drizzle-orm';
|
|
2
3
|
import { mysqlTable, text, json, varchar, uniqueIndex, index, datetime, bigint } from 'drizzle-orm/mysql-core';
|
|
3
|
-
import { createId } from '@paralleldrive/cuid2';
|
|
4
|
-
|
|
5
|
-
// src/drizzle/mysql.ts
|
|
6
|
-
var DIMAH_S3_SCHEMA_VERSION = "2.0.0";
|
|
7
|
-
var runtimeDefaults = {
|
|
8
|
-
id: () => createId(),
|
|
9
|
-
now: () => /* @__PURE__ */ new Date()
|
|
10
|
-
};
|
|
11
4
|
|
|
12
5
|
// src/drizzle/mysql.ts
|
|
6
|
+
var SCHEMA_VERSION = "2.0.0";
|
|
13
7
|
var BINARY = "utf8mb4_bin";
|
|
14
8
|
function id() {
|
|
15
|
-
return string("id").primaryKey().$defaultFn(
|
|
9
|
+
return string("id").primaryKey().$defaultFn(() => createId());
|
|
16
10
|
}
|
|
17
11
|
function string(name, length = 255) {
|
|
18
12
|
return varchar(name, { length }).collate(BINARY);
|
|
@@ -21,7 +15,7 @@ function timestamp(name) {
|
|
|
21
15
|
return datetime(name, { mode: "date", fsp: 3 });
|
|
22
16
|
}
|
|
23
17
|
function timestampNow(name) {
|
|
24
|
-
return timestamp(name).notNull().default(sql`CURRENT_TIMESTAMP(3)`).$defaultFn(
|
|
18
|
+
return timestamp(name).notNull().default(sql`CURRENT_TIMESTAMP(3)`).$defaultFn(() => /* @__PURE__ */ new Date());
|
|
25
19
|
}
|
|
26
20
|
function byteCount(name) {
|
|
27
21
|
return bigint(name, { mode: "number" });
|
|
@@ -110,7 +104,7 @@ var storageFolder = mysqlTable(
|
|
|
110
104
|
);
|
|
111
105
|
var dimahS3Settings = mysqlTable("private_dimah_s3_settings", {
|
|
112
106
|
key: string("key").primaryKey(),
|
|
113
|
-
version: text("value").collate(BINARY).notNull().default(
|
|
107
|
+
version: text("value").collate(BINARY).notNull().default(SCHEMA_VERSION)
|
|
114
108
|
});
|
|
115
109
|
var dimahS3Tables = {
|
|
116
110
|
storageObject,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/drizzle/
|
|
1
|
+
{"version":3,"sources":["../../src/drizzle/mysql.ts"],"names":[],"mappings":";;;;;AAiCA,IAAM,cAAA,GAAiB,OAAA;AAGvB,IAAM,MAAA,GAAS,aAAA;AAEf,SAAS,EAAA,GAAK;AACZ,EAAA,OAAO,MAAA,CAAO,IAAI,CAAA,CACf,UAAA,GACA,UAAA,CAAW,MAAM,UAAU,CAAA;AAChC;AAEA,SAAS,MA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,CAAM,MAAA,EAAQ,GAAG;AAAA;AAC1B;AAEJ;AAMO,IAAM,eAAA,GAAkB,WAAW,2BAAA,EAA6B;AAAA,EACrE,GAAA,EAAK,MAAA,CAAO,KAAK,CAAA,CAAE,UAAA,EAAW;AAAA,EAC9B,OAAA,EAAS,IAAA,CAAK,OAAO,CAAA,CAAE,OAAA,CAAQ,MAAM,CAAA,CAAE,OAAA,EAAQ,CAAE,OAAA,CAAQ,cAAc;AACzE,CAAC;AAOM,IAAM,aAAA,GAAgB;AAAA,EAC3B,aAAA;AAAA,EACA,aAAA;AAAA,EACA,yBAAA,EAA2B;AAC7B","file":"mysql.js","sourcesContent":["/**\n * Drizzle schema for @dimah-s3/db on MySQL 8. Copy this file into your app\n * (`db/schema.ts`) to own the tables and add columns. Keep the table names,\n * the column names, and the `dimahS3Tables` keys: the adapter finds the\n * tables by those keys. A column you add must be nullable or have a default.\n * The plugin does not read or write it.\n *\n * Import `dimahS3Tables` from `@dimah-s3/db/drizzle/mysql` when the tables\n * stay as they are. `drizzle-kit` then follows that import, and a later push\n * drops a column that is not part of it.\n *\n * Columns, collations and indexes match `sql/mysql.sql`, including the\n * prefix indexes on `key`, `folder`, `path` and `parent`. Keys, folders and\n * scopes compare byte for byte (`utf8mb4_bin`), and file names\n * case-insensitively (`utf8mb4_unicode_ci`). Requires `drizzle-orm` and\n * `@paralleldrive/cuid2`.\n */\nimport { createId } from \"@paralleldrive/cuid2\";\nimport { sql } from \"drizzle-orm\";\nimport {\n bigint,\n datetime,\n index,\n json,\n mysqlTable,\n text,\n uniqueIndex,\n varchar,\n type MySqlColumn,\n} from \"drizzle-orm/mysql-core\";\n\ntype StorageObjectStatus = \"pending\" | \"active\" | \"deleted\" | \"purging\";\n\nconst SCHEMA_VERSION = \"2.0.0\";\n\n/** Collation of every text column but `filename`: byte for byte. */\nconst BINARY = \"utf8mb4_bin\";\n\nfunction id() {\n return string(\"id\")\n .primaryKey()\n .$defaultFn(() => createId());\n}\n\nfunction string(name: string, length = 255) {\n return varchar(name, { length }).collate(BINARY);\n}\n\nfunction timestamp(name: string) {\n return datetime(name, { mode: \"date\", fsp: 3 });\n}\n\nfunction timestampNow(name: string) {\n return timestamp(name)\n .notNull()\n .default(sql`CURRENT_TIMESTAMP(3)`)\n .$defaultFn(() => new Date());\n}\n\nfunction byteCount(name: string) {\n return bigint(name, { mode: \"number\" });\n}\n\n/** An index on the first `length` characters of a long column. */\nfunction prefix(column: MySqlColumn, length: number) {\n return sql`${column}(${sql.raw(String(length))})`;\n}\n\n/** The `storage_object` table: one row per tracked object. */\nexport const storageObject = mysqlTable(\n \"storage_object\",\n {\n id: id(),\n scope: string(\"scope\").notNull(),\n bucket: string(\"bucket\").notNull(),\n key: string(\"key\", 1024).notNull(),\n route: string(\"route\").notNull(),\n folder: string(\"folder\", 1024),\n filename: varchar(\"filename\", { length: 255 })\n .collate(\"utf8mb4_unicode_ci\")\n .notNull(),\n contentType: string(\"content_type\"),\n size: byteCount(\"size\"),\n declaredSize: byteCount(\"declared_size\"),\n eTag: string(\"e_tag\"),\n status: string(\"status\", 16).$type<StorageObjectStatus>().notNull(),\n s3Metadata: json(\"s3_metadata\").$type<Record<string, string>>(),\n attributes: json(\"attributes\"),\n acl: string(\"acl\"),\n uploadId: text(\"upload_id\").collate(BINARY),\n uploadToken: string(\"upload_token\", 64),\n expiresAt: timestamp(\"expires_at\"),\n confirmedAt: timestamp(\"confirmed_at\"),\n createdAt: timestampNow(\"created_at\"),\n updatedAt: timestampNow(\"updated_at\"),\n deletedAt: timestamp(\"deleted_at\"),\n },\n (table) => [\n uniqueIndex(\"storage_object_bucket_key_uk\").on(\n table.bucket,\n prefix(table.key, 512),\n ),\n index(\"storage_object_scope_folder_idx\").on(\n table.scope,\n table.status,\n prefix(table.folder, 255),\n table.createdAt,\n ),\n index(\"storage_object_scope_updated_idx\").on(\n table.scope,\n table.status,\n table.updatedAt,\n ),\n index(\"storage_object_scope_filename_idx\").on(\n table.scope,\n table.status,\n table.filename,\n ),\n index(\"storage_object_scope_size_idx\").on(\n table.scope,\n table.status,\n table.size,\n ),\n index(\"storage_object_status_expires_idx\").on(\n table.status,\n table.expiresAt,\n ),\n ],\n);\n\n/** The `storage_folder` table: one row per folder, so empty folders list. */\nexport const storageFolder = mysqlTable(\n \"storage_folder\",\n {\n id: id(),\n scope: string(\"scope\").notNull(),\n path: string(\"path\", 1024).notNull(),\n parent: string(\"parent\", 1024),\n name: string(\"name\").notNull(),\n createdAt: timestampNow(\"created_at\"),\n },\n (table) => [\n uniqueIndex(\"storage_folder_scope_path_uk\").on(\n table.scope,\n prefix(table.path, 512),\n ),\n index(\"storage_folder_scope_parent_idx\").on(\n table.scope,\n prefix(table.parent, 512),\n ),\n ],\n);\n\n/**\n * The FumaDB settings table. The Drizzle adapter reads the schema version\n * from the default of its `version` column, which is stored as `value`.\n */\nexport const dimahS3Settings = mysqlTable(\"private_dimah_s3_settings\", {\n key: string(\"key\").primaryKey(),\n version: text(\"value\").collate(BINARY).notNull().default(SCHEMA_VERSION),\n});\n\n/**\n * Every @dimah-s3/db table. Spread it into your Drizzle schema and keep its\n * keys, because the FumaDB Drizzle adapter finds tables by them:\n * `drizzle({ client, relations: defineRelations({ ...dimahS3Tables }) })`.\n */\nexport const dimahS3Tables = {\n storageObject,\n storageFolder,\n private_dimah_s3_settings: dimahS3Settings,\n};\n"]}
|
package/dist/drizzle/pg.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type StorageObjectStatus = "pending" | "active" | "deleted" | "purging";
|
|
2
2
|
/** The `storage_object` table: one row per tracked object. */
|
|
3
3
|
export declare const storageObject: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
4
4
|
name: "storage_object";
|
|
@@ -960,4 +960,5 @@ export declare const dimahS3Tables: {
|
|
|
960
960
|
isAlias: false;
|
|
961
961
|
}>;
|
|
962
962
|
};
|
|
963
|
+
export {};
|
|
963
964
|
//# sourceMappingURL=pg.d.ts.map
|
package/dist/drizzle/pg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../src/drizzle/pg.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../src/drizzle/pg.ts"],"names":[],"mappings":"AA0BA,KAAK,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAqBxE,8DAA8D;AAC9D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsDzB,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAczB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG1B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIzB,CAAC"}
|
package/dist/drizzle/pg.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
+
import { createId } from '@paralleldrive/cuid2';
|
|
1
2
|
import { sql } from 'drizzle-orm';
|
|
2
3
|
import { pgTable, timestamp, text, json, unique, index, varchar, bigint } from 'drizzle-orm/pg-core';
|
|
3
|
-
import { createId } from '@paralleldrive/cuid2';
|
|
4
|
-
|
|
5
|
-
// src/drizzle/pg.ts
|
|
6
|
-
var DIMAH_S3_SCHEMA_VERSION = "2.0.0";
|
|
7
|
-
var runtimeDefaults = {
|
|
8
|
-
id: () => createId(),
|
|
9
|
-
now: () => /* @__PURE__ */ new Date()
|
|
10
|
-
};
|
|
11
4
|
|
|
12
5
|
// src/drizzle/pg.ts
|
|
6
|
+
var SCHEMA_VERSION = "2.0.0";
|
|
13
7
|
function id() {
|
|
14
|
-
return varchar("id", { length: 255 }).primaryKey().$defaultFn(
|
|
8
|
+
return varchar("id", { length: 255 }).primaryKey().$defaultFn(() => createId());
|
|
15
9
|
}
|
|
16
10
|
function timestampNow(name) {
|
|
17
|
-
return timestamp(name).notNull().default(sql`CURRENT_TIMESTAMP`).$defaultFn(
|
|
11
|
+
return timestamp(name).notNull().default(sql`CURRENT_TIMESTAMP`).$defaultFn(() => /* @__PURE__ */ new Date());
|
|
18
12
|
}
|
|
19
13
|
function byteCount(name) {
|
|
20
14
|
return bigint(name, { mode: "number" });
|
|
@@ -91,7 +85,7 @@ var storageFolder = pgTable(
|
|
|
91
85
|
);
|
|
92
86
|
var dimahS3Settings = pgTable("private_dimah_s3_settings", {
|
|
93
87
|
key: varchar("key", { length: 255 }).primaryKey(),
|
|
94
|
-
version: text("value").notNull().default(
|
|
88
|
+
version: text("value").notNull().default(SCHEMA_VERSION)
|
|
95
89
|
});
|
|
96
90
|
var dimahS3Tables = {
|
|
97
91
|
storageObject,
|
package/dist/drizzle/pg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/drizzle/
|
|
1
|
+
{"version":3,"sources":["../../src/drizzle/pg.ts"],"names":[],"mappings":";;;;;AA4BA,IAAM,cAAA,GAAiB,OAAA;AAEvB,SAAS,EAAA,GAAK;AACZ,EAAA,OAAO,OAAA,CAAQ,IAAA,EAAM,EAAE,MAAA,EAAQ,GAAA,EAAK,CAAA,CACjC,UAAA,EAAW,CACX,UAAA,CAAW,MAAM,QAAA,EAAU,CAAA;AAChC;AAEA,SAAS,aAAa,IAAA,EAAc;AAClC,EAAA,OAAO,SAAA,CAAU,IAAI,CAAA,CAClB,OAAA,EAAQ,CACR,OAAA,CAAQ,GAAA,CAAA,iBAAA,CAAsB,CAAA,CAC9B,UAAA,CAAW,sBAAM,IAAI,IAAA,EAAM,CAAA;AAChC;AAEA,SAAS,UAAU,IAAA,EAAc;AAC/B,EAAA,OAAO,MAAA,CAAO,IAAA,EAAM,EAAE,IAAA,EAAM,UAAU,CAAA;AACxC;AAGO,IAAM,aAAA,GAAgB,OAAA;AAAA,EAC3B,gBAAA;AAAA,EACA;AAAA,IACE,IAAI,EAAA,EAAG;AAAA,IACP,KAAA,EAAO,IAAA,CAAK,OAAO,CAAA,CAAE,OAAA,EAAQ;AAAA,IAC7B,MAAA,EAAQ,IAAA,CAAK,QAAQ,CAAA,CAAE,OAAA,EAAQ;AAAA,IAC/B,GAAA,EAAK,IAAA,CA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AAE,UAAA,EAAW;AAAA,EAChD,SAAS,IAAA,CAAK,OAAO,EAAE,OAAA,EAAQ,CAAE,QAAQ,cAAc;AACzD,CAAC;AAOM,IAAM,aAAA,GAAgB;AAAA,EAC3B,aAAA;AAAA,EACA,aAAA;AAAA,EACA,yBAAA,EAA2B;AAC7B","file":"pg.js","sourcesContent":["/**\n * Drizzle schema for @dimah-s3/db on PostgreSQL. Copy this file into your\n * app (`db/schema.ts`) to own the tables and add columns. Keep the table\n * names, the column names, and the `dimahS3Tables` keys: the adapter finds\n * the tables by those keys. A column you add must be nullable or have a\n * default. The plugin does not read or write it.\n *\n * Import `dimahS3Tables` from `@dimah-s3/db/drizzle/pg` when the tables stay\n * as they are. `drizzle-kit` then follows that import, and a later push\n * drops a column that is not part of it.\n *\n * Matches `sql/pg.sql`. Requires `drizzle-orm` and `@paralleldrive/cuid2`.\n */\nimport { createId } from \"@paralleldrive/cuid2\";\nimport { sql } from \"drizzle-orm\";\nimport {\n bigint,\n index,\n json,\n pgTable,\n text,\n timestamp,\n unique,\n varchar,\n} from \"drizzle-orm/pg-core\";\n\ntype StorageObjectStatus = \"pending\" | \"active\" | \"deleted\" | \"purging\";\n\nconst SCHEMA_VERSION = \"2.0.0\";\n\nfunction id() {\n return varchar(\"id\", { length: 255 })\n .primaryKey()\n .$defaultFn(() => createId());\n}\n\nfunction timestampNow(name: string) {\n return timestamp(name)\n .notNull()\n .default(sql`CURRENT_TIMESTAMP`)\n .$defaultFn(() => new Date());\n}\n\nfunction byteCount(name: string) {\n return bigint(name, { mode: \"number\" });\n}\n\n/** The `storage_object` table: one row per tracked object. */\nexport const storageObject = pgTable(\n \"storage_object\",\n {\n id: id(),\n scope: text(\"scope\").notNull(),\n bucket: text(\"bucket\").notNull(),\n key: text(\"key\").notNull(),\n route: text(\"route\").notNull(),\n folder: text(\"folder\"),\n filename: text(\"filename\").notNull(),\n contentType: text(\"content_type\"),\n size: byteCount(\"size\"),\n declaredSize: byteCount(\"declared_size\"),\n eTag: text(\"e_tag\"),\n status: text(\"status\").$type<StorageObjectStatus>().notNull(),\n s3Metadata: json(\"s3_metadata\").$type<Record<string, string>>(),\n attributes: json(\"attributes\"),\n acl: text(\"acl\"),\n uploadId: text(\"upload_id\"),\n uploadToken: text(\"upload_token\"),\n expiresAt: timestamp(\"expires_at\"),\n confirmedAt: timestamp(\"confirmed_at\"),\n createdAt: timestampNow(\"created_at\"),\n updatedAt: timestampNow(\"updated_at\"),\n deletedAt: timestamp(\"deleted_at\"),\n },\n (table) => [\n unique(\"storage_object_bucket_key_uk\").on(table.bucket, table.key),\n index(\"storage_object_scope_folder_idx\").on(\n table.scope,\n table.status,\n table.folder,\n table.createdAt,\n ),\n index(\"storage_object_scope_updated_idx\").on(\n table.scope,\n table.status,\n table.updatedAt,\n ),\n index(\"storage_object_scope_filename_idx\").on(\n table.scope,\n table.status,\n table.filename,\n ),\n index(\"storage_object_scope_size_idx\").on(\n table.scope,\n table.status,\n table.size,\n ),\n index(\"storage_object_status_expires_idx\").on(\n table.status,\n table.expiresAt,\n ),\n ],\n);\n\n/** The `storage_folder` table: one row per folder, so empty folders list. */\nexport const storageFolder = pgTable(\n \"storage_folder\",\n {\n id: id(),\n scope: text(\"scope\").notNull(),\n path: text(\"path\").notNull(),\n parent: text(\"parent\"),\n name: text(\"name\").notNull(),\n createdAt: timestampNow(\"created_at\"),\n },\n (table) => [\n unique(\"storage_folder_scope_path_uk\").on(table.scope, table.path),\n index(\"storage_folder_scope_parent_idx\").on(table.scope, table.parent),\n ],\n);\n\n/**\n * The FumaDB settings table. The Drizzle adapter reads the schema version\n * from the default of its `version` column, which is stored as `value`.\n */\nexport const dimahS3Settings = pgTable(\"private_dimah_s3_settings\", {\n key: varchar(\"key\", { length: 255 }).primaryKey(),\n version: text(\"value\").notNull().default(SCHEMA_VERSION),\n});\n\n/**\n * Every @dimah-s3/db table. Spread it into your Drizzle schema and keep its\n * keys, because the FumaDB Drizzle adapter finds tables by them:\n * `drizzle({ client, relations: defineRelations({ ...dimahS3Tables }) })`.\n */\nexport const dimahS3Tables = {\n storageObject,\n storageFolder,\n private_dimah_s3_settings: dimahS3Settings,\n};\n"]}
|
package/dist/drizzle/shared.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Schema version the Drizzle tables describe.
|
|
3
|
-
*
|
|
2
|
+
* Schema version the Drizzle tables describe. Each dialect file inlines the
|
|
3
|
+
* same string so a copied schema does not import this module. The parity
|
|
4
|
+
* test checks both against the FumaDB schema.
|
|
4
5
|
*/
|
|
5
6
|
export declare const DIMAH_S3_SCHEMA_VERSION = "2.0.0";
|
|
6
|
-
/**
|
|
7
|
-
* The FumaDB Drizzle adapter leaves runtime defaults to Drizzle, so the
|
|
8
|
-
* tables fill ids and timestamps the way the other adapters do: a cuid and
|
|
9
|
-
* the app's clock. The SQL defaults only keep generated DDL in line with
|
|
10
|
-
* `sql/<dialect>.sql`.
|
|
11
|
-
*/
|
|
12
|
-
export declare const runtimeDefaults: {
|
|
13
|
-
id: () => string;
|
|
14
|
-
now: () => Date;
|
|
15
|
-
};
|
|
16
7
|
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/drizzle/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/drizzle/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,UAAU,CAAC"}
|
package/dist/drizzle/sqlite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type StorageObjectStatus = "pending" | "active" | "deleted" | "purging";
|
|
2
2
|
/** The `storage_object` table: one row per tracked object. */
|
|
3
3
|
export declare const storageObject: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
4
4
|
name: "storage_object";
|
|
@@ -1020,4 +1020,5 @@ export declare const dimahS3Tables: {
|
|
|
1020
1020
|
isAlias: false;
|
|
1021
1021
|
}>;
|
|
1022
1022
|
};
|
|
1023
|
+
export {};
|
|
1023
1024
|
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/drizzle/sqlite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/drizzle/sqlite.ts"],"names":[],"mappings":"AAwBA,KAAK,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAyBxE,8DAA8D;AAC9D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwDzB,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAczB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG1B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;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