create-guren-app 1.10.0 → 1.10.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/dist/cli.js CHANGED
@@ -1517,34 +1517,27 @@ async function loadDatabaseConfig(driver) {
1517
1517
  throw new Error(`Could not read the ${driver} database config template at "${databaseConfigTemplatePath(driver)}". This build of create-guren-app may be incomplete — please report it at https://github.com/gurenjs/guren/issues and try \`npm create guren-app@latest\` meanwhile.`, { cause });
1518
1518
  }
1519
1519
  }
1520
- function generateSchema(driver) {
1521
- if (driver === "postgres") return `import { pgTable, serial, text, timestamp } from '@guren/orm/drizzle/pg'
1522
-
1523
- export const users = pgTable('users', {
1524
- id: serial('id').primaryKey(),
1525
- name: text('name').notNull(),
1526
- email: text('email').notNull(),
1527
- createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
1528
- })
1529
- `;
1530
- if (driver === "mysql") return `import { mysqlTable, int, varchar, timestamp } from '@guren/orm/drizzle/mysql'
1531
-
1532
- export const users = mysqlTable('users', {
1533
- id: int('id').primaryKey().autoincrement(),
1534
- name: varchar('name', { length: 255 }).notNull(),
1535
- email: varchar('email', { length: 255 }).notNull(),
1536
- createdAt: timestamp('created_at').notNull().defaultNow(),
1537
- })
1538
- `;
1539
- return `import { sqliteTable, integer, text } from '@guren/orm/drizzle/sqlite'
1540
-
1541
- export const users = sqliteTable('users', {
1542
- id: integer('id').primaryKey({ autoIncrement: true }),
1543
- name: text('name').notNull(),
1544
- email: text('email').notNull(),
1545
- createdAt: text('created_at').notNull().$defaultFn(() => new Date().toISOString()),
1546
- })
1547
- `;
1520
+ /**
1521
+ * The generic single-`users`-table schema, one real source per driver under
1522
+ * `templates/database/<driver>/db/schema.ts` — the same verbatim-copy shape
1523
+ * `config/database.ts` uses, and for the same reason (a string-emitted file
1524
+ * is a file no tsconfig covers). Each dialect imports from its own
1525
+ * `@guren/orm/drizzle/<dialect>` barrel, the same modules `guren add auth` /
1526
+ * `add resource` merge new columns into.
1527
+ *
1528
+ * Named `db/schema.ts`, not `db/schema.<driver>.ts`: the suffixed name means
1529
+ * "a template ships its own schema" (see `schemaVariantPath`), and these are
1530
+ * the fallback for templates that ship none.
1531
+ */
1532
+ function databaseSchemaTemplatePath(driver) {
1533
+ return join(TEMPLATES_ROOT, "database", driver, "db/schema.ts");
1534
+ }
1535
+ async function loadFallbackSchema(driver) {
1536
+ try {
1537
+ return await readFile(databaseSchemaTemplatePath(driver), "utf8");
1538
+ } catch (cause) {
1539
+ throw new Error(`Could not read the ${driver} database schema template at "${databaseSchemaTemplatePath(driver)}". This build of create-guren-app may be incomplete — please report it at https://github.com/gurenjs/guren/issues and try \`npm create guren-app@latest\` meanwhile.`, { cause });
1540
+ }
1548
1541
  }
1549
1542
  /**
1550
1543
  * Templates whose app code needs more than the single `users` table above ship
@@ -1566,45 +1559,27 @@ function schemaVariantPath(destination, driver) {
1566
1559
  }
1567
1560
  async function resolveSchema(destination, driver) {
1568
1561
  const shipped = (await Promise.all(DATABASE_DRIVERS.map(async (name) => await fileExists(schemaVariantPath(destination, name)) ? name : null))).filter((name) => name !== null);
1569
- if (shipped.length === 0) return generateSchema(driver);
1562
+ if (shipped.length === 0) return await loadFallbackSchema(driver);
1570
1563
  if (!shipped.includes(driver)) throw new Error(`This template ships a database schema for ${shipped.join(", ")} but not for ${driver}. This build of create-guren-app is incomplete — please report it at https://github.com/gurenjs/guren/issues.`);
1571
1564
  return readFile(schemaVariantPath(destination, driver), "utf8");
1572
1565
  }
1573
- function generateDrizzleConfig(driver) {
1574
- const { url, dialect } = DATABASE_DEFAULTS[driver];
1575
- return `import { defineConfig } from 'drizzle-kit'
1576
- ${driver !== "sqlite" ? "" : `
1577
- const filename = process.env.DATABASE_URL ?? '${url}'
1578
-
1579
1566
  /**
1580
- * DATABASE_URL is read by two different SQLite implementations that disagree
1581
- * about URI filenames: the app opens it with \`bun:sqlite\`, which honours them,
1582
- * while drizzle-kit opens it with \`node:sqlite\`, which does not. So \`file:\` is
1583
- * not a shared spelling of anything — \`file:local.db\` migrates the app into
1584
- * \`local.db\` and drizzle-kit into a file *named* \`file:local.db\`. The safe set
1585
- * is what both agree on: plain paths, and \`:memory:\`.
1586
- *
1587
- * The scheme must be two characters or more, since no registered scheme is one
1588
- * letter while \`C:/data/app.db\` is a Windows drive path.
1589
- */
1590
- const uriScheme = /^([a-z][a-z0-9+.-]+):/i.exec(filename)
1591
-
1592
- if (uriScheme) {
1593
- throw new Error(
1594
- \`DATABASE_URL must be a plain file path for SQLite, but starts with "\${uriScheme[1]}:". \` +
1595
- 'Point it at a file such as ${url}, or use ":memory:".',
1596
- )
1597
- }
1598
- `}
1599
- export default defineConfig({
1600
- schema: './db/schema.ts',
1601
- out: './db/migrations',
1602
- dialect: '${dialect}',
1603
- dbCredentials: {
1604
- url: ${driver === "sqlite" ? "filename" : `process.env.DATABASE_URL ?? '${url}'`},
1605
- },
1606
- })
1607
- `;
1567
+ * `drizzle.config.ts` ships the same way as `config/database.ts` above: one
1568
+ * real source per driver, copied verbatim. The only variance the deleted
1569
+ * string generator had was driver-keyed — the URL and dialect from
1570
+ * `DATABASE_DEFAULTS`, plus the SQLite-only DATABASE_URL guard that Postgres
1571
+ * and MySQL must not inherit (they take a real connection string here, so a
1572
+ * scheme check would reject every valid value they have).
1573
+ */
1574
+ function drizzleConfigTemplatePath(driver) {
1575
+ return join(TEMPLATES_ROOT, "database", driver, "drizzle.config.ts");
1576
+ }
1577
+ async function loadDrizzleConfig(driver) {
1578
+ try {
1579
+ return await readFile(drizzleConfigTemplatePath(driver), "utf8");
1580
+ } catch (cause) {
1581
+ throw new Error(`Could not read the ${driver} drizzle config template at "${drizzleConfigTemplatePath(driver)}". This build of create-guren-app may be incomplete — please report it at https://github.com/gurenjs/guren/issues and try \`npm create guren-app@latest\` meanwhile.`, { cause });
1582
+ }
1608
1583
  }
1609
1584
  /**
1610
1585
  * True when the driver runs in a container the scaffolder provisions — the one
@@ -1653,11 +1628,13 @@ async function applyDatabaseConfig(destination, driver) {
1653
1628
  const dockerCompose = generateDockerCompose(driver);
1654
1629
  const schema = await resolveSchema(destination, driver);
1655
1630
  const databaseConfig = await loadDatabaseConfig(driver);
1631
+ const drizzleConfig = await loadDrizzleConfig(driver);
1632
+ await mkdir(join(destination, "db"), { recursive: true });
1656
1633
  await Promise.all([
1657
1634
  writeFile(join(destination, "config/database.ts"), databaseConfig, "utf8"),
1658
1635
  writeFile(join(destination, "db/schema.ts"), schema, "utf8"),
1659
1636
  ...DATABASE_DRIVERS.map((name) => rm(schemaVariantPath(destination, name), { force: true })),
1660
- writeFile(join(destination, "drizzle.config.ts"), generateDrizzleConfig(driver), "utf8"),
1637
+ writeFile(join(destination, "drizzle.config.ts"), drizzleConfig, "utf8"),
1661
1638
  dockerCompose ? writeFile(join(destination, "docker-compose.yml"), dockerCompose, "utf8") : Promise.resolve(),
1662
1639
  ...[".env", ".env.example"].map(async (envFile) => {
1663
1640
  const envPath = join(destination, envFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guren-app",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -18,13 +18,13 @@
18
18
  "test": "bun test"
19
19
  },
20
20
  "dependencies": {
21
- "@guren/cli": "^2.11.0",
22
- "@guren/core": "^1.10.0",
21
+ "@guren/cli": "^2.13.0",
22
+ "@guren/core": "^1.12.0",
23
23
  "@guren/orm": "^2.6.1",
24
24
  "drizzle-orm": "1.0.0-rc.4"
25
25
  },
26
26
  "devDependencies": {
27
- "@guren/testing": "^1.6.3",
27
+ "@guren/testing": "^1.8.0",
28
28
  "bun-types": "^1.3.1",
29
29
  "drizzle-kit": "1.0.0-rc.4",
30
30
  "typescript": "^5.4.0"
@@ -0,0 +1,8 @@
1
+ import { mysqlTable, int, varchar, timestamp } from '@guren/orm/drizzle/mysql'
2
+
3
+ export const users = mysqlTable('users', {
4
+ id: int('id').primaryKey().autoincrement(),
5
+ name: varchar('name', { length: 255 }).notNull(),
6
+ email: varchar('email', { length: 255 }).notNull(),
7
+ createdAt: timestamp('created_at').notNull().defaultNow(),
8
+ })
@@ -8,8 +8,8 @@ export default defineConfig({
8
8
  // schema: ['./db/schema.ts', './modules/*/db/schema.ts'].
9
9
  schema: './db/schema.ts',
10
10
  out: './db/migrations',
11
- dialect: 'sqlite',
11
+ dialect: 'mysql',
12
12
  dbCredentials: {
13
- url: process.env.DATABASE_URL ?? './data/guren.db',
13
+ url: process.env.DATABASE_URL ?? 'mysql://guren:guren@localhost:33306/guren',
14
14
  },
15
15
  })
@@ -0,0 +1,8 @@
1
+ import { pgTable, serial, text, timestamp } from '@guren/orm/drizzle/pg'
2
+
3
+ export const users = pgTable('users', {
4
+ id: serial('id').primaryKey(),
5
+ name: text('name').notNull(),
6
+ email: text('email').notNull(),
7
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
8
+ })
@@ -8,8 +8,8 @@ export default defineConfig({
8
8
  // schema: ['./db/schema.ts', './modules/*/db/schema.ts'].
9
9
  schema: './db/schema.ts',
10
10
  out: './db/migrations',
11
- dialect: 'sqlite',
11
+ dialect: 'postgresql',
12
12
  dbCredentials: {
13
- url: process.env.DATABASE_URL ?? './data/guren.db',
13
+ url: process.env.DATABASE_URL ?? 'postgres://guren:guren@localhost:54322/guren',
14
14
  },
15
15
  })
@@ -0,0 +1,37 @@
1
+ import { defineConfig } from 'drizzle-kit'
2
+
3
+ const filename = process.env.DATABASE_URL ?? './data/guren.db'
4
+
5
+ /**
6
+ * DATABASE_URL is read by two different SQLite implementations that disagree
7
+ * about URI filenames: the app opens it with `bun:sqlite`, which honours them,
8
+ * while drizzle-kit opens it with `node:sqlite`, which does not. So `file:` is
9
+ * not a shared spelling of anything — `file:local.db` migrates the app into
10
+ * `local.db` and drizzle-kit into a file *named* `file:local.db`. The safe set
11
+ * is what both agree on: plain paths, and `:memory:`.
12
+ *
13
+ * The scheme must be two characters or more, since no registered scheme is one
14
+ * letter while `C:/data/app.db` is a Windows drive path.
15
+ */
16
+ const uriScheme = /^([a-z][a-z0-9+.-]+):/i.exec(filename)
17
+
18
+ if (uriScheme) {
19
+ throw new Error(
20
+ `DATABASE_URL must be a plain file path for SQLite, but starts with "${uriScheme[1]}:". ` +
21
+ 'Point it at a file such as ./data/guren.db, or use ":memory:".',
22
+ )
23
+ }
24
+
25
+ export default defineConfig({
26
+ // `guren make:module` wires each modules/<name>/db/schema.ts into this
27
+ // file automatically via a re-export, so this single path is enough by
28
+ // default. If you'd rather point drizzle-kit at every module schema
29
+ // directly instead, `schema` also accepts an array of paths/globs, e.g.
30
+ // schema: ['./db/schema.ts', './modules/*/db/schema.ts'].
31
+ schema: './db/schema.ts',
32
+ out: './db/migrations',
33
+ dialect: 'sqlite',
34
+ dbCredentials: {
35
+ url: filename,
36
+ },
37
+ })
@@ -19,8 +19,8 @@
19
19
  "db:seed": "bunx guren db:seed"
20
20
  },
21
21
  "dependencies": {
22
- "@guren/cli": "^2.11.0",
23
- "@guren/core": "^1.10.0",
22
+ "@guren/cli": "^2.13.0",
23
+ "@guren/core": "^1.12.0",
24
24
  "@guren/inertia-client": "^1.1.2",
25
25
  "@guren/orm": "^2.6.1",
26
26
  "@inertiajs/react": "^3.6.1",
@@ -30,7 +30,7 @@
30
30
  "zod": "^4.4.3"
31
31
  },
32
32
  "devDependencies": {
33
- "@guren/testing": "^1.6.3",
33
+ "@guren/testing": "^1.8.0",
34
34
  "@tailwindcss/vite": "^4.2.2",
35
35
  "@types/react": "^19.0.0",
36
36
  "@types/react-dom": "^19.0.0",
@@ -1,3 +0,0 @@
1
- import { sqliteTable, integer, text } from '@guren/orm/drizzle/sqlite'
2
-
3
- export const schema = {}