@dimah-s3/db 2.0.0-beta.5 → 2.0.0-beta.6
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 +15 -6
- package/dist/adapters/drizzle.d.ts +2 -3
- package/dist/adapters/drizzle.d.ts.map +1 -1
- package/dist/adapters/kysely.d.ts +1 -1
- package/dist/adapters/prisma.d.ts +1 -1
- package/dist/cli.d.ts +17 -12
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +41 -74
- package/dist/cli.js.map +1 -1
- package/dist/fuma-db.d.ts +19 -22
- package/dist/fuma-db.d.ts.map +1 -1
- package/dist/index.js +59 -79
- package/dist/index.js.map +1 -1
- package/dist/schema/schema.d.ts +30 -50
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/store/folder-store.d.ts.map +1 -1
- package/dist/store/map-row.d.ts +2 -8
- package/dist/store/map-row.d.ts.map +1 -1
- package/dist/store/object-store.d.ts.map +1 -1
- package/package.json +8 -26
- package/dist/drizzle/mysql.d.ts +0 -1057
- package/dist/drizzle/mysql.d.ts.map +0 -1
- package/dist/drizzle/mysql.js +0 -120
- package/dist/drizzle/mysql.js.map +0 -1
- package/dist/drizzle/pg.d.ts +0 -994
- package/dist/drizzle/pg.d.ts.map +0 -1
- package/dist/drizzle/pg.js +0 -104
- package/dist/drizzle/pg.js.map +0 -1
- package/dist/drizzle/shared.d.ts +0 -7
- package/dist/drizzle/shared.d.ts.map +0 -1
- package/dist/drizzle/sqlite.d.ts +0 -1056
- package/dist/drizzle/sqlite.d.ts.map +0 -1
- package/dist/drizzle/sqlite.js +0 -107
- package/dist/drizzle/sqlite.js.map +0 -1
- package/prisma/dimah-s3.prisma +0 -81
- package/sql/mysql.sql +0 -60
- package/sql/pg.sql +0 -53
- package/sql/sqlite.sql +0 -55
- package/src/drizzle/mysql.ts +0 -175
- package/src/drizzle/pg.ts +0 -146
- package/src/drizzle/sqlite.ts +0 -150
package/src/drizzle/pg.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
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
|
-
};
|
package/src/drizzle/sqlite.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
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
|
-
};
|