create-prisma 0.4.2-pr.53.194.1 → 0.4.2-pr.53.196.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/dist/cli.mjs +1 -1
- package/dist/{create-BlE_5uZk.mjs → create-Bpm3olVB.mjs} +3 -3
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
- package/templates/create/_shared/README.md.hbs +2 -0
- package/templates/create/_shared/src/prisma/db.ts.hbs +20 -10
- package/templates/create/_shared/src/prisma/seed.ts.hbs +29 -33
- package/templates/create/_shared/src/prisma/starter-data.ts.hbs +36 -0
- package/templates/create/_shared/src/prisma/users.ts.hbs +2 -0
- package/templates/create/astro/src/pages/index.astro.hbs +1 -1
- package/templates/create/next/src/app/page.tsx.hbs +1 -1
- package/templates/create/nuxt/app/pages/index.vue.hbs +1 -1
- package/templates/create/svelte/src/routes/+page.svelte.hbs +1 -1
- package/templates/create/tanstack-start/src/routes/index.tsx.hbs +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -40,7 +40,7 @@ async function getAnonymousId() {
|
|
|
40
40
|
}
|
|
41
41
|
function getCommonProperties() {
|
|
42
42
|
return {
|
|
43
|
-
"cli-version": "0.4.2-pr.53.
|
|
43
|
+
"cli-version": "0.4.2-pr.53.196.1",
|
|
44
44
|
"node-version": process.version,
|
|
45
45
|
platform: process.platform,
|
|
46
46
|
arch: process.arch
|
|
@@ -473,8 +473,8 @@ const dependencyVersionMap = {
|
|
|
473
473
|
"@elysiajs/node": "^1.4.5",
|
|
474
474
|
"@prisma/cli": "8.0.0-rc.2",
|
|
475
475
|
"@prisma/cli-engine": "8.0.0-rc.2",
|
|
476
|
-
"@prisma/composer": "0.
|
|
477
|
-
"@prisma/composer-prisma-cloud": "0.
|
|
476
|
+
"@prisma/composer": "0.7.0",
|
|
477
|
+
"@prisma/composer-prisma-cloud": "0.7.0",
|
|
478
478
|
"@prisma/orm-mongo": "8.0.0-rc.1",
|
|
479
479
|
"@prisma/orm-postgres": "8.0.0-rc.1",
|
|
480
480
|
"@sveltejs/adapter-node": "^5.3.2",
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as DatabaseProviderSchema, i as CreateTemplateSchema, n as AuthoringStyleSchema, o as PackageManagerSchema, r as CreateCommandInputSchema, t as runCreateCommand } from "./create-
|
|
2
|
+
import { a as DatabaseProviderSchema, i as CreateTemplateSchema, n as AuthoringStyleSchema, o as PackageManagerSchema, r as CreateCommandInputSchema, t as runCreateCommand } from "./create-Bpm3olVB.mjs";
|
|
3
3
|
import { os } from "@orpc/server";
|
|
4
4
|
import { createCli } from "trpc-cli";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
|
|
7
7
|
//#region src/index.ts
|
|
8
|
-
const CLI_VERSION = "0.4.2-pr.53.
|
|
8
|
+
const CLI_VERSION = "0.4.2-pr.53.196.1";
|
|
9
9
|
const CreateCliInputSchema = z.tuple([z.string().trim().min(1, "Please enter a valid project name").optional().describe("Project name / directory"), CreateCommandInputSchema]);
|
|
10
10
|
function normalizeCreateCliInput(input) {
|
|
11
11
|
const [projectName, options] = input;
|
package/package.json
CHANGED
|
@@ -18,6 +18,8 @@ This builds the app and starts it with Composer. PostgreSQL projects get a local
|
|
|
18
18
|
|
|
19
19
|
The deploy script builds the framework output, provisions Prisma Postgres when selected, applies migrations, and deploys the app to Prisma Compute.
|
|
20
20
|
|
|
21
|
+
The starter users are inserted idempotently on the first database query. `{{runScriptCommand packageManager "db:seed"}}` can also seed an explicit `DATABASE_URL`; for local PostgreSQL it reuses the database created by `dev:composer`.
|
|
22
|
+
|
|
21
23
|
{{#if (eq provider "mongo")}}
|
|
22
24
|
MongoDB is not provisioned by Composer. Set `MONGODB_URL` before running Composer locally or deploying.
|
|
23
25
|
{{/if}}
|
|
@@ -15,10 +15,9 @@ function loadComposerDatabase() {
|
|
|
15
15
|
|
|
16
16
|
export const db =
|
|
17
17
|
loadComposerDatabase() ??
|
|
18
|
-
|
|
19
|
-
contractJson,
|
|
20
|
-
|
|
21
|
-
});
|
|
18
|
+
(process.env.DATABASE_URL
|
|
19
|
+
? postgres<Contract>({ contractJson, url: process.env.DATABASE_URL })
|
|
20
|
+
: postgres<Contract>({ contractJson }));
|
|
22
21
|
{{else}}
|
|
23
22
|
import mongo from "@prisma/orm-mongo/runtime";
|
|
24
23
|
|
|
@@ -26,16 +25,27 @@ import service from "../../service.ts";
|
|
|
26
25
|
import type { Contract } from "./{{#if (eq authoring "typescript")}}generated/{{/if}}contract.d.ts";
|
|
27
26
|
import contractJson from "./{{#if (eq authoring "typescript")}}generated/{{/if}}contract.json" with { type: "json" };
|
|
28
27
|
|
|
29
|
-
function getDatabaseUrl(): string {
|
|
28
|
+
function getDatabaseUrl(): string | undefined {
|
|
30
29
|
try {
|
|
31
30
|
return service.input().databaseUrl.expose();
|
|
32
31
|
} catch {
|
|
33
|
-
return process.env.DATABASE_URL
|
|
32
|
+
return process.env.DATABASE_URL;
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})
|
|
36
|
+
const databaseUrl = getDatabaseUrl();
|
|
37
|
+
|
|
38
|
+
export const db = databaseUrl
|
|
39
|
+
? mongo<Contract>({ contractJson, url: databaseUrl })
|
|
40
|
+
: mongo<Contract>({ contractJson });
|
|
41
41
|
{{/if}}
|
|
42
|
+
|
|
43
|
+
let connection: Promise<void> | undefined;
|
|
44
|
+
|
|
45
|
+
export function connectDatabase(): Promise<void> {
|
|
46
|
+
connection ??= db.connect().then(() => undefined).catch((error: unknown) => {
|
|
47
|
+
connection = undefined;
|
|
48
|
+
throw error;
|
|
49
|
+
});
|
|
50
|
+
return connection;
|
|
51
|
+
}
|
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
{{#if (requiresDotenvConfigImport packageManager)}}
|
|
2
1
|
import "dotenv/config";
|
|
3
|
-
{{
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const seedUsers = [
|
|
7
|
-
{ email: "alice@prisma.io", username: "alice", name: "Alice" },
|
|
8
|
-
{ email: "bob@prisma.io", username: "bob", name: "Bob" },
|
|
9
|
-
{ email: "carol@prisma.io", username: "carol", name: "Carol" },
|
|
10
|
-
];
|
|
2
|
+
{{#if (eq provider "postgres")}}
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
11
4
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
async function loadComposerDevDatabaseUrl(): Promise<string | undefined> {
|
|
6
|
+
try {
|
|
7
|
+
const contents = await readFile(
|
|
8
|
+
new URL("../../.prisma-composer/dev/env.json", import.meta.url),
|
|
9
|
+
"utf8",
|
|
10
|
+
);
|
|
11
|
+
const env = JSON.parse(contents) as Record<string, unknown>;
|
|
12
|
+
const value = env.COMPOSER_APP_DATABASE_URL;
|
|
13
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
14
|
+
} catch {
|
|
15
|
+
return undefined;
|
|
22
16
|
}
|
|
17
|
+
}
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
19
|
+
process.env.DATABASE_URL ??= await loadComposerDevDatabaseUrl();
|
|
20
|
+
{{/if}}
|
|
21
|
+
|
|
22
|
+
if (!process.env.DATABASE_URL) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"DATABASE_URL is not set. Run dev:composer once to create the local database, or set DATABASE_URL explicitly.",
|
|
25
|
+
);
|
|
27
26
|
}
|
|
28
|
-
{{else}}
|
|
29
|
-
try {
|
|
30
|
-
for (const user of seedUsers) {
|
|
31
|
-
const existingUser = await db.orm.public.User.where({ email: user.email }).first();
|
|
32
|
-
if (!existingUser) {
|
|
33
|
-
await db.orm.public.User.create(user);
|
|
34
|
-
createdCount += 1;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
27
|
|
|
38
|
-
|
|
28
|
+
const [{ db }, { seedStarterData }] = await Promise.all([
|
|
29
|
+
import("./db.ts"),
|
|
30
|
+
import("./starter-data.ts"),
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await seedStarterData();
|
|
35
|
+
console.log("Starter users are ready.");
|
|
39
36
|
} finally {
|
|
40
37
|
await db.close();
|
|
41
38
|
}
|
|
42
|
-
{{/if}}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { connectDatabase, db } from "./db.ts";
|
|
2
|
+
|
|
3
|
+
const starterUsers = [
|
|
4
|
+
{ email: "alice@prisma.io", username: "alice", name: "Alice" },
|
|
5
|
+
{ email: "bob@prisma.io", username: "bob", name: "Bob" },
|
|
6
|
+
{ email: "carol@prisma.io", username: "carol", name: "Carol" },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
let seed: Promise<void> | undefined;
|
|
10
|
+
|
|
11
|
+
async function seedOnce(): Promise<void> {
|
|
12
|
+
await connectDatabase();
|
|
13
|
+
|
|
14
|
+
{{#if (eq provider "mongo")}}
|
|
15
|
+
for (const user of starterUsers) {
|
|
16
|
+
const existingUser = await db.orm.users.where({ email: user.email }).first();
|
|
17
|
+
if (!existingUser) await db.orm.users.create(user);
|
|
18
|
+
}
|
|
19
|
+
{{else}}
|
|
20
|
+
for (const user of starterUsers) {
|
|
21
|
+
await db.orm.public.User.upsert({
|
|
22
|
+
create: user,
|
|
23
|
+
update: {},
|
|
24
|
+
conflictOn: { email: user.email },
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
{{/if}}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function seedStarterData(): Promise<void> {
|
|
31
|
+
seed ??= seedOnce().catch((error: unknown) => {
|
|
32
|
+
seed = undefined;
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
return seed;
|
|
36
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
|
|
3
3
|
import { db } from "./db.ts";
|
|
4
|
+
import { seedStarterData } from "./starter-data.ts";
|
|
4
5
|
|
|
5
6
|
export { db };
|
|
6
7
|
|
|
7
8
|
export async function listUsers(limit = 10) {
|
|
9
|
+
await seedStarterData();
|
|
8
10
|
{{#if (eq provider "mongo")}}
|
|
9
11
|
const users = [];
|
|
10
12
|
|
|
@@ -44,7 +44,7 @@ const users = await listUsers(10).catch(() => undefined);
|
|
|
44
44
|
then refresh.
|
|
45
45
|
</p>
|
|
46
46
|
) : users.length === 0 ? (
|
|
47
|
-
<p class="empty">No users
|
|
47
|
+
<p class="empty">No users found.</p>
|
|
48
48
|
) : (
|
|
49
49
|
<ul class="users">
|
|
50
50
|
{users.map((user) => (
|
|
@@ -33,7 +33,7 @@ export default async function Home() {
|
|
|
33
33
|
then refresh.
|
|
34
34
|
</p>
|
|
35
35
|
) : users.length === 0 ? (
|
|
36
|
-
<p className="empty">No users
|
|
36
|
+
<p className="empty">No users found.</p>
|
|
37
37
|
) : (
|
|
38
38
|
<ul className="users">
|
|
39
39
|
{users.map((user) => (
|
|
@@ -51,7 +51,7 @@ function formatCreatedAt(value: string): string {
|
|
|
51
51
|
\{{ data.error }} Run <code>contract:emit</code> and apply your schema, then refresh.
|
|
52
52
|
</p>
|
|
53
53
|
<p v-else-if="!data?.users?.length" class="empty">
|
|
54
|
-
No users
|
|
54
|
+
No users found.
|
|
55
55
|
</p>
|
|
56
56
|
<ul v-else class="users">
|
|
57
57
|
<li v-for="user in data.users" :key="user.id">
|
|
@@ -54,7 +54,7 @@ function Home() {
|
|
|
54
54
|
then refresh.
|
|
55
55
|
</p>
|
|
56
56
|
) : users.length === 0 ? (
|
|
57
|
-
<p className="empty">No users
|
|
57
|
+
<p className="empty">No users found.</p>
|
|
58
58
|
) : (
|
|
59
59
|
<ul className="users">
|
|
60
60
|
{users.map((user) => (
|