create-m5kdev 0.28.7 → 0.28.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/minimal-app/apps/server/drizzle/db.ts.tpl +26 -26
- package/templates/minimal-app/apps/server/drizzle/guard.ts.tpl +36 -0
- package/templates/minimal-app/apps/server/drizzle/meta/0000_snapshot.json.tpl +1889 -1889
- package/templates/minimal-app/apps/server/drizzle/meta/_journal.json.tpl +12 -12
- package/templates/minimal-app/apps/server/drizzle/reset.ts.tpl +40 -33
- package/templates/minimal-app/apps/server/drizzle/seed.e2e.ts.tpl +246 -244
- package/templates/minimal-app/apps/server/drizzle/seed.ts.tpl +183 -181
- package/templates/minimal-app/apps/server/drizzle/sync.ts.tpl +16 -14
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { createClient } from "@libsql/client";
|
|
2
|
-
import { drizzle } from "drizzle-orm/libsql";
|
|
3
|
-
import * as schema from "../src/schema";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Standalone DB handle for scripts (seed, maintenance). Deliberately does NOT
|
|
7
|
-
* import ./app — constructing the backend app opens Redis/queue connections
|
|
8
|
-
* that keep short-lived scripts alive forever. The running server gets its own
|
|
9
|
-
* connection through createBackendApp.
|
|
10
|
-
*/
|
|
11
|
-
const databaseUrl = process.env.DATABASE_URL ?? "file:./local.db";
|
|
12
|
-
const syncUrl = process.env.TURSO_DATABASE_URL;
|
|
13
|
-
const authToken = process.env.TURSO_AUTH_TOKEN;
|
|
14
|
-
|
|
15
|
-
export const isRemote = syncUrl && authToken;
|
|
16
|
-
|
|
17
|
-
const client = createClient(
|
|
18
|
-
isRemote ? { url: databaseUrl, syncUrl, authToken } : { url: databaseUrl }
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
export const orm = drizzle(client, { schema });
|
|
22
|
-
|
|
23
|
-
export type Orm = typeof orm;
|
|
24
|
-
export type Schema = typeof schema;
|
|
25
|
-
|
|
26
|
-
export { schema };
|
|
1
|
+
import { createClient } from "@libsql/client";
|
|
2
|
+
import { drizzle } from "drizzle-orm/libsql";
|
|
3
|
+
import * as schema from "../src/schema";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Standalone DB handle for scripts (seed, maintenance). Deliberately does NOT
|
|
7
|
+
* import ./app — constructing the backend app opens Redis/queue connections
|
|
8
|
+
* that keep short-lived scripts alive forever. The running server gets its own
|
|
9
|
+
* connection through createBackendApp.
|
|
10
|
+
*/
|
|
11
|
+
const databaseUrl = process.env.DATABASE_URL ?? "file:./local.db";
|
|
12
|
+
const syncUrl = process.env.TURSO_DATABASE_URL;
|
|
13
|
+
const authToken = process.env.TURSO_AUTH_TOKEN;
|
|
14
|
+
|
|
15
|
+
export const isRemote = syncUrl && authToken;
|
|
16
|
+
|
|
17
|
+
const client = createClient(
|
|
18
|
+
isRemote ? { url: databaseUrl, syncUrl, authToken } : { url: databaseUrl }
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const orm = drizzle(client, { schema });
|
|
22
|
+
|
|
23
|
+
export type Orm = typeof orm;
|
|
24
|
+
export type Schema = typeof schema;
|
|
25
|
+
|
|
26
|
+
export { schema };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import net from "node:net";
|
|
2
|
+
|
|
3
|
+
const CONNECT_TIMEOUT_MS = 500;
|
|
4
|
+
|
|
5
|
+
function isPortInUse(port: number): Promise<boolean> {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
const socket = net.connect({ port, host: "127.0.0.1" });
|
|
8
|
+
const done = (result: boolean) => {
|
|
9
|
+
socket.destroy();
|
|
10
|
+
resolve(result);
|
|
11
|
+
};
|
|
12
|
+
socket.setTimeout(CONNECT_TIMEOUT_MS);
|
|
13
|
+
socket.once("connect", () => done(true));
|
|
14
|
+
socket.once("timeout", () => done(false));
|
|
15
|
+
socket.once("error", () => done(false));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The dev server holds its own libsql connection on the local database file —
|
|
21
|
+
* an embedded replica when Turso is configured. A second process syncing or
|
|
22
|
+
* deleting that file corrupts the WAL, so db scripts must not run while the
|
|
23
|
+
* server is up. Best-effort check: only the conventional PORT is probed.
|
|
24
|
+
*/
|
|
25
|
+
export async function ensureDevServerStopped(): Promise<void> {
|
|
26
|
+
if (process.env.SKIP_DB_GUARD === "true") return;
|
|
27
|
+
const databaseUrl = process.env.DATABASE_URL ?? "file:./local.db";
|
|
28
|
+
if (!databaseUrl.startsWith("file:")) return;
|
|
29
|
+
const port = Number.parseInt(process.env.PORT ?? "8080", 10);
|
|
30
|
+
if (Number.isNaN(port) || !(await isPortInUse(port))) return;
|
|
31
|
+
console.error(
|
|
32
|
+
`[drizzle] A server is listening on port ${port} and holds ${databaseUrl}. ` +
|
|
33
|
+
"Stop the dev server first, or set SKIP_DB_GUARD=true to override."
|
|
34
|
+
);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|