create-protobase 0.51.3 → 0.52.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/bin/create-protobase.mjs +2 -0
- package/dist/database-steps.js +1 -0
- package/dist/database-wizard.js +12 -3
- package/dist/next-steps.js +4 -3
- package/dist/templates/erp/db/drop.ts +7 -1
- package/dist/templates/erp/db/migrate.ts +4 -3
- package/dist/templates/erp/package.json +6 -6
- package/dist/templates/real-estate/db/drop.ts +7 -1
- package/dist/templates/real-estate/db/migrate.ts +4 -3
- package/dist/templates/real-estate/package.json +6 -6
- package/dist/templates/scratch/db/migrate.ts +4 -3
- package/dist/templates/scratch/package.json +6 -6
- package/package.json +2 -2
package/bin/create-protobase.mjs
CHANGED
package/dist/database-steps.js
CHANGED
|
@@ -50,6 +50,7 @@ const databaseSteps = ({ templateDir, secret, tools, terminal, loadScaffold = pr
|
|
|
50
50
|
await install(dir, manager);
|
|
51
51
|
},
|
|
52
52
|
listTables: async (dir, url) => (await loadScaffold(dir)).listTables(url),
|
|
53
|
+
useSupabaseUsers: async (dir) => (await loadScaffold(dir)).useSupabaseUsers(path.resolve(dir), terminal.print),
|
|
53
54
|
importTables: async (dir, url, { excluded, ui, review }) => {
|
|
54
55
|
if (review && !terminal.ask) throw new Error("reviewing each column needs a terminal");
|
|
55
56
|
const scaffold = await loadScaffold(dir);
|
package/dist/database-wizard.js
CHANGED
|
@@ -42,13 +42,22 @@ const createFromDatabase = async (url, dir, terminal, steps) => {
|
|
|
42
42
|
const manager = steps.tools.bun ? "bun" : "npm";
|
|
43
43
|
print(`\nWrote the project to ${folder}. Installing its packages with ${manager}...\n`);
|
|
44
44
|
await steps.install(folder, manager);
|
|
45
|
-
const { tables, skipped } = await steps.listTables(folder, url);
|
|
45
|
+
const { tables, skipped, supabaseSchemas } = await steps.listTables(folder, url);
|
|
46
|
+
const supabase = supabaseSchemas.length > 0;
|
|
47
|
+
if (supabase) {
|
|
48
|
+
print(`\n${database} is a Supabase database: the project signs in on Supabase's own auth.users.\n`);
|
|
49
|
+
await steps.useSupabaseUsers(folder);
|
|
50
|
+
}
|
|
46
51
|
if (tables.length === 0) print(`\n${database} has no tables to import${skipped.length > 0 ? `: it leaves out ${skipped.join(", ")}` : ""}. The project starts without resources.\n`);
|
|
47
52
|
else {
|
|
48
53
|
print(tableMenu(database, tables, skipped));
|
|
49
|
-
|
|
54
|
+
const choices = await askChoices(tables, terminal);
|
|
55
|
+
await steps.importTables(folder, url, {
|
|
56
|
+
...choices,
|
|
57
|
+
excluded: [...choices.excluded, ...supabaseSchemas]
|
|
58
|
+
});
|
|
50
59
|
}
|
|
51
|
-
print(`\nCreated a Protobase project in ${folder} on the database ${database}, which it has only read. Next:\n\n${databaseNextSteps(folder, steps.tools)}`);
|
|
60
|
+
print(`\nCreated a Protobase project in ${folder} on the database ${database}, which it has only read. Next:\n\n${databaseNextSteps(folder, steps.tools, supabase)}`);
|
|
52
61
|
};
|
|
53
62
|
//#endregion
|
|
54
63
|
export { createFromDatabase };
|
package/dist/next-steps.js
CHANGED
|
@@ -25,11 +25,12 @@ const nextSteps = (dir, scripts, port, tools) => {
|
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* What to run in a new project on an existing database, its packages installed, until its admin app serves: the first
|
|
28
|
-
* of them is the first that writes to the database, adding the auth schema sign-in keeps its users in
|
|
28
|
+
* of them is the first that writes to the database, adding the auth schema sign-in keeps its users in, or on a
|
|
29
|
+
* Supabase database, `supabase`, Better Auth's tables next to Supabase's auth.users.
|
|
29
30
|
*/
|
|
30
|
-
const databaseNextSteps = (dir, tools) => withBun([
|
|
31
|
+
const databaseNextSteps = (dir, tools, supabase = false) => withBun([
|
|
31
32
|
`cd ${dir}`,
|
|
32
|
-
"bun run db:migrate # the first write to the database: the auth schema, and
|
|
33
|
+
supabase ? "bun run db:migrate # the first write to the database: Better Auth's tables next to auth.users, and migrations.applied" : "bun run db:migrate # the first write to the database: the auth schema, and migrations.applied",
|
|
33
34
|
"bun run protobase users create you@example.com --generate-password",
|
|
34
35
|
"bun run dev # http://localhost:5173"
|
|
35
36
|
], tools);
|
|
@@ -3,7 +3,13 @@ import { connect } from './connection'
|
|
|
3
3
|
const sql = connect({ max: 1 })
|
|
4
4
|
|
|
5
5
|
await sql.unsafe('drop schema if exists core, crm, catalog, sales, inventory, hr cascade')
|
|
6
|
-
await sql.unsafe('drop
|
|
6
|
+
await sql.unsafe('drop schema if exists migrations cascade')
|
|
7
|
+
await sql.unsafe('drop table if exists public.seed_info')
|
|
8
|
+
// The record an earlier Protobase kept, by its columns: a `schema_migrations` another migration tool owns stays.
|
|
9
|
+
const [earlier] = await sql`
|
|
10
|
+
select count(*) = 2 as ours from information_schema.columns
|
|
11
|
+
where table_schema = 'public' and table_name = 'schema_migrations' and column_name in ('name', 'applied_at')`
|
|
12
|
+
if (earlier!.ours) await sql.unsafe('drop table public.schema_migrations')
|
|
7
13
|
console.log('dropped all erp schemas')
|
|
8
14
|
|
|
9
15
|
await sql.end()
|
|
@@ -16,12 +16,13 @@ const files = (await readdir(directory)).filter((file) => file.endsWith('.sql'))
|
|
|
16
16
|
|
|
17
17
|
const applied = await sql.begin(async (tx) => {
|
|
18
18
|
await tx`select pg_advisory_xact_lock(${lockKey})`
|
|
19
|
-
await tx`create
|
|
20
|
-
|
|
19
|
+
await tx`create schema if not exists migrations`
|
|
20
|
+
await tx`create table if not exists migrations.applied (name text primary key, applied_at timestamptz not null default now())`
|
|
21
|
+
const done = new Set((await tx`select name from migrations.applied`).map((row) => row.name))
|
|
21
22
|
const pending = files.filter((file) => !done.has(file))
|
|
22
23
|
for (const file of pending) {
|
|
23
24
|
await tx.unsafe(await readFile(directory + file, 'utf8'))
|
|
24
|
-
await tx`insert into
|
|
25
|
+
await tx`insert into migrations.applied (name) values (${file})`
|
|
25
26
|
}
|
|
26
27
|
return pending
|
|
27
28
|
})
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"react": "^19.3.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@protobase/cli": "^0.
|
|
28
|
-
"@protobase/config": "^0.
|
|
29
|
-
"@protobase/layout": "^0.
|
|
30
|
-
"@protobase/schema": "^0.
|
|
31
|
-
"@protobase/server": "^0.
|
|
32
|
-
"@protobase/ui": "^0.
|
|
27
|
+
"@protobase/cli": "^0.52.1",
|
|
28
|
+
"@protobase/config": "^0.52.1",
|
|
29
|
+
"@protobase/layout": "^0.52.1",
|
|
30
|
+
"@protobase/schema": "^0.52.1",
|
|
31
|
+
"@protobase/server": "^0.52.1",
|
|
32
|
+
"@protobase/ui": "^0.52.1",
|
|
33
33
|
"@types/node": "^22.20.5",
|
|
34
34
|
"@types/pg": "^8.23.1",
|
|
35
35
|
"@types/react": "^19.3.0",
|
|
@@ -3,7 +3,13 @@ import { connect } from './connection'
|
|
|
3
3
|
const sql = connect({ max: 1 })
|
|
4
4
|
|
|
5
5
|
await sql.unsafe('drop schema if exists core, portfolio, leasing, billing, maintenance cascade')
|
|
6
|
-
await sql.unsafe('drop
|
|
6
|
+
await sql.unsafe('drop schema if exists migrations cascade')
|
|
7
|
+
await sql.unsafe('drop table if exists public.seed_info')
|
|
8
|
+
// The record an earlier Protobase kept, by its columns: a `schema_migrations` another migration tool owns stays.
|
|
9
|
+
const [earlier] = await sql`
|
|
10
|
+
select count(*) = 2 as ours from information_schema.columns
|
|
11
|
+
where table_schema = 'public' and table_name = 'schema_migrations' and column_name in ('name', 'applied_at')`
|
|
12
|
+
if (earlier!.ours) await sql.unsafe('drop table public.schema_migrations')
|
|
7
13
|
console.log('dropped all real estate schemas')
|
|
8
14
|
|
|
9
15
|
await sql.end()
|
|
@@ -16,12 +16,13 @@ const files = (await readdir(directory)).filter((file) => file.endsWith('.sql'))
|
|
|
16
16
|
|
|
17
17
|
const applied = await sql.begin(async (tx) => {
|
|
18
18
|
await tx`select pg_advisory_xact_lock(${lockKey})`
|
|
19
|
-
await tx`create
|
|
20
|
-
|
|
19
|
+
await tx`create schema if not exists migrations`
|
|
20
|
+
await tx`create table if not exists migrations.applied (name text primary key, applied_at timestamptz not null default now())`
|
|
21
|
+
const done = new Set((await tx`select name from migrations.applied`).map((row) => row.name))
|
|
21
22
|
const pending = files.filter((file) => !done.has(file))
|
|
22
23
|
for (const file of pending) {
|
|
23
24
|
await tx.unsafe(await readFile(directory + file, 'utf8'))
|
|
24
|
-
await tx`insert into
|
|
25
|
+
await tx`insert into migrations.applied (name) values (${file})`
|
|
25
26
|
}
|
|
26
27
|
return pending
|
|
27
28
|
})
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"react": "^19.3.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@protobase/cli": "^0.
|
|
28
|
-
"@protobase/config": "^0.
|
|
29
|
-
"@protobase/layout": "^0.
|
|
30
|
-
"@protobase/schema": "^0.
|
|
31
|
-
"@protobase/server": "^0.
|
|
32
|
-
"@protobase/ui": "^0.
|
|
27
|
+
"@protobase/cli": "^0.52.1",
|
|
28
|
+
"@protobase/config": "^0.52.1",
|
|
29
|
+
"@protobase/layout": "^0.52.1",
|
|
30
|
+
"@protobase/schema": "^0.52.1",
|
|
31
|
+
"@protobase/server": "^0.52.1",
|
|
32
|
+
"@protobase/ui": "^0.52.1",
|
|
33
33
|
"@types/node": "^22.20.5",
|
|
34
34
|
"@types/pg": "^8.23.1",
|
|
35
35
|
"@types/react": "^19.3.0",
|
|
@@ -16,12 +16,13 @@ const files = (await readdir(directory)).filter((file) => file.endsWith('.sql'))
|
|
|
16
16
|
|
|
17
17
|
const applied = await sql.begin(async (tx) => {
|
|
18
18
|
await tx`select pg_advisory_xact_lock(${lockKey})`
|
|
19
|
-
await tx`create
|
|
20
|
-
|
|
19
|
+
await tx`create schema if not exists migrations`
|
|
20
|
+
await tx`create table if not exists migrations.applied (name text primary key, applied_at timestamptz not null default now())`
|
|
21
|
+
const done = new Set((await tx`select name from migrations.applied`).map((row) => row.name))
|
|
21
22
|
const pending = files.filter((file) => !done.has(file))
|
|
22
23
|
for (const file of pending) {
|
|
23
24
|
await tx.unsafe(await readFile(directory + file, 'utf8'))
|
|
24
|
-
await tx`insert into
|
|
25
|
+
await tx`insert into migrations.applied (name) values (${file})`
|
|
25
26
|
}
|
|
26
27
|
return pending
|
|
27
28
|
})
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"react": "^19.3.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@protobase/cli": "^0.
|
|
25
|
-
"@protobase/config": "^0.
|
|
26
|
-
"@protobase/layout": "^0.
|
|
27
|
-
"@protobase/schema": "^0.
|
|
28
|
-
"@protobase/server": "^0.
|
|
29
|
-
"@protobase/ui": "^0.
|
|
24
|
+
"@protobase/cli": "^0.52.1",
|
|
25
|
+
"@protobase/config": "^0.52.1",
|
|
26
|
+
"@protobase/layout": "^0.52.1",
|
|
27
|
+
"@protobase/schema": "^0.52.1",
|
|
28
|
+
"@protobase/server": "^0.52.1",
|
|
29
|
+
"@protobase/ui": "^0.52.1",
|
|
30
30
|
"@types/node": "^22.20.5",
|
|
31
31
|
"@types/pg": "^8.23.1",
|
|
32
32
|
"@types/react": "^19.3.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-protobase",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.1",
|
|
4
4
|
"description": "npm create protobase: starts a new Protobase project from one of its presets, or on an existing Postgres database.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"postgres": "^3.4.9"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@protobase/cli": "0.
|
|
31
|
+
"@protobase/cli": "0.52.1"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|