@protobase/cli 0.129.0 → 0.130.0
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/auth/config-organizations.js +15 -0
- package/dist/auth/register.js +8 -2
- package/dist/auth/write-migration.js +34 -12
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +1 -0
- package/dist/config/project-modules.js +64 -0
- package/dist/config/read-only-queries.js +9 -0
- package/dist/config/user-tables-config.js +1 -1
- package/dist/dev/dev-jobs.js +12 -6
- package/dist/dev/entry.js +12 -19
- package/dist/doctor/capture-files.js +3 -3
- package/dist/doctor/startup.js +2 -4
- package/dist/migration/apply-migrations.js +9 -6
- package/dist/migration/baseline/read-live-modules.js +31 -0
- package/dist/migration/baseline/read-live-store.js +50 -0
- package/dist/migration/baseline/write-baseline.js +80 -0
- package/dist/migration/migrate-project.js +3 -3
- package/dist/migration/migration-project.js +29 -15
- package/dist/migration/older-code/catalog.js +34 -0
- package/dist/migration/older-code/contractions.js +86 -0
- package/dist/migration/older-code/lint-files.js +55 -0
- package/dist/migration/older-code/refusal.js +9 -0
- package/dist/migration/older-code/trial.js +58 -0
- package/dist/migration/parts.js +8 -104
- package/dist/migration/record/after-file.js +20 -2
- package/dist/migration/register.js +56 -15
- package/dist/migration/release/release-record.js +9 -7
- package/dist/migration/release/release-steps.js +15 -3
- package/dist/migration/snapshot/auth-difference.js +111 -12
- package/dist/migration/snapshot/auth-target.js +9 -3
- package/dist/migration/snapshot/check.js +26 -9
- package/dist/migration/snapshot/custom.js +6 -3
- package/dist/migration/snapshot/drop.js +5 -1
- package/dist/migration/snapshot/header.js +11 -4
- package/dist/migration/snapshot/module-changes.js +22 -0
- package/dist/migration/snapshot/module-prompts.js +28 -0
- package/dist/migration/snapshot/module-sections.js +38 -0
- package/dist/migration/snapshot/next-snapshot.js +24 -8
- package/dist/migration/snapshot/off-choice.js +11 -0
- package/dist/migration/snapshot/organizations-off-facts.js +49 -0
- package/dist/migration/snapshot/revival-rows.js +34 -0
- package/dist/migration/snapshot/run-migration.js +82 -16
- package/dist/migration/snapshot/snapshot-file.js +7 -0
- package/dist/migration/snapshot/terminal-prompts.js +21 -0
- package/dist/migration/snapshot/write-file.js +1 -1
- package/dist/migration/summary.js +3 -2
- package/dist/organizations/api.js +4 -2
- package/dist/organizations/commands.js +27 -10
- package/dist/organizations/pin-source.js +20 -0
- package/dist/organizations/pin.js +40 -0
- package/dist/organizations/register.js +20 -12
- package/dist/scaffold/protobase-tables.js +2 -2
- package/dist/serve/create-admin.js +6 -3
- package/dist/serve/lifecycle.js +2 -2
- package/dist/serve/migrate-release.js +1 -1
- package/dist/serve/relay-check.js +7 -8
- package/dist/serve/startup-checks.js +12 -22
- package/dist/supabase/load-phase.js +3 -1
- package/dist/supabase/project-users.js +4 -1
- package/dist/users/commands.js +44 -6
- package/dist/users/load-auth.js +9 -3
- package/dist/users/manage.js +16 -1
- package/dist/users/register.js +28 -25
- package/dist/users/set-disabled.js +3 -2
- package/dist/users/users-api.js +9 -3
- package/dist/worker/start-worker.js +7 -4
- package/package.json +8 -8
- package/skills/protobase/references/features/api-functions.md +1 -0
- package/skills/protobase/references/features/build-and-run.md +3 -2
- package/skills/protobase/references/features/sign-in-and-accounts.md +2 -1
- package/skills/protobase/references/guides/api-functions.md +27 -2
- package/skills/protobase/references/guides/deploy.md +2 -2
- package/skills/protobase/references/reference/assistant.md +1 -1
- package/skills/protobase/references/reference/auth.md +52 -17
- package/skills/protobase/references/reference/calls.md +1 -1
- package/skills/protobase/references/reference/cli.md +41 -27
- package/skills/protobase/references/reference/comments.md +1 -1
- package/skills/protobase/references/reference/config/api.md +1 -1
- package/skills/protobase/references/reference/config/jobs-and-events.md +1 -1
- package/skills/protobase/references/reference/config/sign-in.md +22 -4
- package/skills/protobase/references/reference/config.md +1 -1
- package/skills/protobase/references/reference/data-config.md +9 -9
- package/skills/protobase/references/reference/derived.md +1 -1
- package/skills/protobase/references/reference/email.md +2 -2
- package/skills/protobase/references/reference/events.md +2 -2
- package/skills/protobase/references/reference/history.md +1 -1
- package/skills/protobase/references/reference/jobs.md +5 -5
- package/skills/protobase/references/reference/live.md +2 -2
- package/skills/protobase/references/reference/notifications.md +4 -4
- package/skills/protobase/references/reference/personal-access-tokens.md +2 -2
- package/skills/protobase/references/reference/realtime-relay.md +1 -1
- package/skills/protobase/references/reference/status.md +2 -2
- package/skills/protobase/references/reference/supabase-rest.md +1 -1
- package/skills/protobase/references/reference/user-tables.md +1 -1
- package/skills/protobase/references/reference/webhooks.md +1 -1
- package/dist/migration/snapshot/lint-custom.js +0 -23
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { loadProjectAuth } from "../users/load-auth.js";
|
|
2
|
+
import { loadConfigOrganizations } from "../auth/config-organizations.js";
|
|
2
3
|
import { writeAuthMigration } from "../auth/write-migration.js";
|
|
3
4
|
import { planAuthConfig, sharedUsersConfig, sharedUsersSchema } from "./auth-config.js";
|
|
4
5
|
import { writeMigration } from "./migration-files.js";
|
|
@@ -24,12 +25,14 @@ const useSupabaseUsers = async (projectDir, out) => {
|
|
|
24
25
|
await authConfig.write();
|
|
25
26
|
if (storeMigrations.length > 0) out(`removed ${storeMigrations.length} migrations of Protobase's own user table: Supabase's users replace it\n`);
|
|
26
27
|
out(`pointed ${relative(authConfig.file)} at ${sharedUsersSchema}.users, a view over auth.users\n`);
|
|
28
|
+
const organizations = await loadConfigOrganizations(projectDir);
|
|
27
29
|
const authFile = await writeAuthMigration({
|
|
28
30
|
auth: await loadProjectAuth(projectDir),
|
|
29
31
|
projectDir,
|
|
30
32
|
dir: migrationsDir,
|
|
31
33
|
name: "auth",
|
|
32
|
-
writer: "create protobase"
|
|
34
|
+
writer: "create protobase",
|
|
35
|
+
organizations
|
|
33
36
|
});
|
|
34
37
|
if (authFile) out(`wrote ${relative(authFile)}, Better Auth's tables in ${sharedUsersSchema}, pointing at auth.users\n`);
|
|
35
38
|
const usersFile = await writeMigration(migrationsDir, "supabase_users", sharedUsersMigration());
|
package/dist/users/commands.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { pinLine, resolveOptionalPin, scopeOf } from "../organizations/pin.js";
|
|
2
|
+
import { parseRoleList } from "../organizations/commands.js";
|
|
1
3
|
import { resolvePassword } from "./password.js";
|
|
4
|
+
import { everyOrganization } from "@protobase/query";
|
|
2
5
|
//#region src/users/commands.ts
|
|
3
6
|
const githubId = /^[1-9][0-9]*$/;
|
|
4
7
|
const shownAs = (role, labels) => {
|
|
@@ -10,7 +13,8 @@ const createUserCommand = async (api, options, deps, out) => {
|
|
|
10
13
|
if (!options.email.includes("@")) throw new Error(`"${options.email}" is not an email address`);
|
|
11
14
|
if (options.githubId !== void 0 && !githubId.test(options.githubId)) throw new Error(`"${options.githubId}" is not a GitHub user id, a number such as 583231`);
|
|
12
15
|
const { password, generated } = await resolvePassword(options, deps);
|
|
13
|
-
const
|
|
16
|
+
const first = !await api.hasUsers();
|
|
17
|
+
const role = first ? "admin" : options.role;
|
|
14
18
|
const user = await api.createUser({
|
|
15
19
|
email: options.email,
|
|
16
20
|
...password !== void 0 && { password },
|
|
@@ -24,10 +28,44 @@ const createUserCommand = async (api, options, deps, out) => {
|
|
|
24
28
|
const { labels } = await api.roles();
|
|
25
29
|
out(`Created ${user.role} ${user.email}${shownAs(user.role, labels)}${options.githubId ? `, linked to GitHub user ${options.githubId}` : ""}\n`);
|
|
26
30
|
if (generated) out(`Password (shown once): ${password}\n`);
|
|
31
|
+
return {
|
|
32
|
+
email: user.email,
|
|
33
|
+
first
|
|
34
|
+
};
|
|
27
35
|
};
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Creates the user (`createUserCommand`) and, with organizations, adds them to the pinned organization, or to none
|
|
38
|
+
* with `--all-organizations`. The pin is resolved first, so an unknown organization creates nobody.
|
|
39
|
+
*/
|
|
40
|
+
const createMemberCommand = async (api, options, deps, out) => {
|
|
41
|
+
if (options.allOrganizations && !api.organizationsOn) throw new Error("--all-organizations needs organizations: turn on auth.organizations in the config");
|
|
42
|
+
if (options.allOrganizations && options.organization !== void 0) throw new Error("Pass --organization or --all-organizations, not both");
|
|
43
|
+
const pin = options.allOrganizations ? void 0 : await resolveOptionalPin(api, options, "users create");
|
|
44
|
+
const user = await createUserCommand(api, options, deps, out);
|
|
45
|
+
if (options.allOrganizations) out(`${user.email} joins no organization\n`);
|
|
46
|
+
if (!pin || "every" in pin) return;
|
|
47
|
+
if (user.first && await api.isMember(pin.organization.id, user.email)) {
|
|
48
|
+
out(`${user.email} owns ${pin.organization.slug}\n`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const appRoles = parseRoleList(options.appRoles);
|
|
52
|
+
await api.addMember({
|
|
53
|
+
organization: pin.organization.id,
|
|
54
|
+
email: user.email,
|
|
55
|
+
...options.orgRole && { role: options.orgRole },
|
|
56
|
+
...appRoles && { appRoles }
|
|
57
|
+
});
|
|
58
|
+
out(`Added ${user.email} to ${pin.organization.slug}${options.orgRole ? ` as ${options.orgRole}` : ""}\n`);
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Prints the users, oldest first, a page at a time as the store pages them; the first page sets the columns' width. With
|
|
62
|
+
* organizations, the members of the pinned organization, or every user with `--all-organizations`.
|
|
63
|
+
*/
|
|
64
|
+
const listUsersCommand = async (api, options, out) => {
|
|
65
|
+
const pin = await resolveOptionalPin(api, options, "users list", () => everyOrganization("protobase users list: --all-organizations"));
|
|
66
|
+
if (pin) out(pinLine(pin));
|
|
67
|
+
const scope = pin && scopeOf(pin);
|
|
68
|
+
let page = await api.listUsers(scope);
|
|
31
69
|
if (page.users.length === 0) {
|
|
32
70
|
out("No users yet. Create the first admin with: protobase users create you@example.com\n");
|
|
33
71
|
return;
|
|
@@ -37,7 +75,7 @@ const listUsersCommand = async (api, out) => {
|
|
|
37
75
|
for (;;) {
|
|
38
76
|
for (const user of page.users) out(`${user.email.padEnd(width)} ${user.role.padEnd(8)} ${user.createdAt}${user.banned ? " disabled" : ""}\n`);
|
|
39
77
|
if (!page.next) return;
|
|
40
|
-
page = await api.listUsers(page.next);
|
|
78
|
+
page = await api.listUsers(scope, page.next);
|
|
41
79
|
}
|
|
42
80
|
};
|
|
43
81
|
const listRolesCommand = async (api, out) => {
|
|
@@ -45,4 +83,4 @@ const listRolesCommand = async (api, out) => {
|
|
|
45
83
|
for (const role of roles) out(`${role}${role === defaultRole ? " (default for new users)" : ""}\n`);
|
|
46
84
|
};
|
|
47
85
|
//#endregion
|
|
48
|
-
export { createUserCommand, listRolesCommand, listUsersCommand };
|
|
86
|
+
export { createMemberCommand, createUserCommand, listRolesCommand, listUsersCommand };
|
package/dist/users/load-auth.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { loadNearestEnvFile } from "../dev/env.js";
|
|
2
2
|
import { projectNotifications, projectWorkflows } from "../config/project-parts.js";
|
|
3
3
|
import { projectAuth } from "../config/build-project.js";
|
|
4
|
+
import { configModules } from "../config/project-modules.js";
|
|
4
5
|
import { loadSourceConfig } from "../config/source-config.js";
|
|
5
6
|
import { withDevUrl } from "../config/tool-url.js";
|
|
6
7
|
import { openAppDatabase } from "../project/pg-db.js";
|
|
7
8
|
import pg from "pg";
|
|
8
9
|
import { releaseConnectionsWithUsers, removeDevicesWithUsers, removeHistoryWithUsers } from "@protobase/server";
|
|
9
10
|
//#region src/users/load-auth.ts
|
|
11
|
+
const loadToolConfig = async (projectDir) => {
|
|
12
|
+
loadNearestEnvFile(projectDir);
|
|
13
|
+
return withDevUrl(await loadSourceConfig(projectDir, { command: "tool" }), projectDir);
|
|
14
|
+
};
|
|
15
|
+
/** The schema modules the config of the project in `projectDir` needs (`configModules`). */
|
|
16
|
+
const loadProjectModules = async (projectDir) => configModules(await loadToolConfig(projectDir));
|
|
10
17
|
/**
|
|
11
18
|
* The sign-in of the project in `projectDir`, built from its config's `auth` over DATABASE_URL, with only the plugins
|
|
12
19
|
* it turns on, at the project's dev address when it sets no `url` (`withDevUrl`); `undefined` when sign-in is off.
|
|
@@ -16,8 +23,7 @@ import { releaseConnectionsWithUsers, removeDevicesWithUsers, removeHistoryWithU
|
|
|
16
23
|
* reporting a token it left valid on stderr.
|
|
17
24
|
*/
|
|
18
25
|
const loadSignIn = async (projectDir) => {
|
|
19
|
-
|
|
20
|
-
const config = await withDevUrl(await loadSourceConfig(projectDir, { command: "tool" }), projectDir);
|
|
26
|
+
const config = await loadToolConfig(projectDir);
|
|
21
27
|
if (!config.auth) return;
|
|
22
28
|
if (!process.env.DATABASE_URL) throw new Error("No database: set DATABASE_URL");
|
|
23
29
|
const database = openAppDatabase(pg, process.env.DATABASE_URL);
|
|
@@ -38,4 +44,4 @@ const loadProjectAuth = async (projectDir) => {
|
|
|
38
44
|
return auth;
|
|
39
45
|
};
|
|
40
46
|
//#endregion
|
|
41
|
-
export { loadProjectAuth, loadSignIn };
|
|
47
|
+
export { loadProjectAuth, loadProjectModules, loadSignIn };
|
package/dist/users/manage.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { checkPinnedUser, pinLine, resolveOptionalPin } from "../organizations/pin.js";
|
|
2
|
+
import { everyOrganization } from "@protobase/query";
|
|
1
3
|
//#region src/users/manage.ts
|
|
4
|
+
const reachUser = async (api, options, command, wide, out) => {
|
|
5
|
+
const pin = await resolveOptionalPin(api, options, command, wide);
|
|
6
|
+
if (!pin) return;
|
|
7
|
+
await checkPinnedUser(api, pin, options.email);
|
|
8
|
+
out(pinLine(pin));
|
|
9
|
+
};
|
|
2
10
|
const deleteUserCommand = async (api, options, confirm, out) => {
|
|
11
|
+
await reachUser(api, options, "users delete", () => everyOrganization("protobase users delete: --all-organizations"), out);
|
|
3
12
|
if (!options.yes) {
|
|
4
13
|
if ((await confirm(`This permanently deletes ${options.email}. Type the email to confirm: `)).trim() !== options.email) throw new Error("The typed email does not match; nothing was deleted");
|
|
5
14
|
}
|
|
@@ -7,10 +16,16 @@ const deleteUserCommand = async (api, options, confirm, out) => {
|
|
|
7
16
|
out(`Deleted ${options.email}\n`);
|
|
8
17
|
};
|
|
9
18
|
const setRoleCommand = async (api, options, out) => {
|
|
10
|
-
|
|
19
|
+
await reachUser(api, options, "users set-role", () => everyOrganization("protobase users set-role: --all-organizations"), out);
|
|
20
|
+
const user = await api.setUserRole({
|
|
21
|
+
email: options.email,
|
|
22
|
+
role: options.role
|
|
23
|
+
});
|
|
11
24
|
out(`${user.email} is now ${user.role}\n`);
|
|
12
25
|
};
|
|
13
26
|
const setDisabledCommand = async (api, options, out) => {
|
|
27
|
+
const command = options.disabled ? "users disable" : "users enable";
|
|
28
|
+
await reachUser(api, options, command, () => everyOrganization(options.disabled ? "protobase users disable: --all-organizations" : "protobase users enable: --all-organizations"), out);
|
|
14
29
|
await api.setUserBanned({
|
|
15
30
|
email: options.email,
|
|
16
31
|
banned: options.disabled
|
package/dist/users/register.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pinOptions } from "../organizations/register.js";
|
|
1
2
|
import { parseTtl } from "./ttl.js";
|
|
2
3
|
import { Option } from "commander";
|
|
3
4
|
import { createInterface } from "node:readline/promises";
|
|
@@ -21,57 +22,56 @@ const ask = async (question) => {
|
|
|
21
22
|
const finish = (code) => process.exit(code);
|
|
22
23
|
const registerUsers = (program) => {
|
|
23
24
|
const users = program.command("users").description("Manage the admin users of the project in the current directory");
|
|
24
|
-
users.command("create").description("Create a user; the first user is always an admin").argument("<email>").option("--name <name>", "display name").option("--role <role>", "role for users after the first (default: the project's default role; see `users roles`)").option("--password-stdin", "read the password from stdin", false).option("--generate-password", "generate a strong password and print it once", false).option("--no-password", "no password: the user signs in by emailed code, passkey or a sign-in provider").option("--github-id <id>", "link the user to this GitHub user id, so signing in with GitHub finds them whatever their address").option("--
|
|
25
|
+
pinOptions(users.command("create").description("Create a user; the first user is always an admin. With organizations, they join the organization; with --all-organizations, none")).argument("<email>").option("--name <name>", "display name").option("--role <role>", "role for users after the first (default: the project's default role; see `users roles`)").option("--password-stdin", "read the password from stdin", false).option("--generate-password", "generate a strong password and print it once", false).option("--no-password", "no password: the user signs in by emailed code, passkey or a sign-in provider").option("--github-id <id>", "link the user to this GitHub user id, so signing in with GitHub finds them whatever their address").option("--org-role <role>", "with organizations: owner, admin or member in the organization (default member)").option("--app-roles <roles>", "with organizations: app roles in the organization, comma separated").addOption(new Option("--password <value>").hideHelp()).action(async (email, opts) => {
|
|
25
26
|
const { readHidden, rejectPasswordArgument } = await import("./password.js");
|
|
26
27
|
rejectPasswordArgument(opts.password);
|
|
27
|
-
const [{
|
|
28
|
-
|
|
29
|
-
import("./users-api.js"),
|
|
30
|
-
import("../organizations/api.js"),
|
|
31
|
-
import("../organizations/commands.js"),
|
|
32
|
-
loadAuth()
|
|
33
|
-
]);
|
|
34
|
-
await createUserCommand(usersApi(auth), {
|
|
28
|
+
const [{ createMemberCommand }, api] = await Promise.all([import("./commands.js"), projectApi()]);
|
|
29
|
+
await createMemberCommand(api, {
|
|
35
30
|
email,
|
|
36
31
|
name: opts.name,
|
|
37
32
|
role: opts.role,
|
|
38
33
|
passwordStdin: opts.passwordStdin,
|
|
39
34
|
generatePassword: opts.generatePassword,
|
|
40
35
|
noPassword: opts.password === false,
|
|
41
|
-
githubId: opts.githubId
|
|
42
|
-
}, {
|
|
43
|
-
stdin: process.stdin,
|
|
44
|
-
prompt: readHidden
|
|
45
|
-
}, out);
|
|
46
|
-
if (opts.organization) await addMemberCommand(organizationsApi(auth), {
|
|
36
|
+
githubId: opts.githubId,
|
|
47
37
|
organization: opts.organization,
|
|
48
|
-
|
|
38
|
+
allOrganizations: opts.allOrganizations,
|
|
49
39
|
orgRole: opts.orgRole,
|
|
50
40
|
appRoles: opts.appRoles
|
|
41
|
+
}, {
|
|
42
|
+
stdin: process.stdin,
|
|
43
|
+
prompt: readHidden
|
|
51
44
|
}, out);
|
|
52
45
|
finish(0);
|
|
53
46
|
});
|
|
54
|
-
users.command("delete").description("Delete a user (refuses the last admin)").argument("<email>").option("--yes", "skip the confirmation", false).action(async (email, opts) => {
|
|
47
|
+
pinOptions(users.command("delete").description("Delete a user (refuses the last admin)")).argument("<email>").option("--yes", "skip the confirmation", false).action(async (email, opts) => {
|
|
55
48
|
const { deleteUserCommand } = await import("./manage.js");
|
|
56
49
|
await deleteUserCommand(await projectApi(), {
|
|
57
50
|
email,
|
|
58
|
-
yes: opts.yes
|
|
51
|
+
yes: opts.yes,
|
|
52
|
+
organization: opts.organization,
|
|
53
|
+
allOrganizations: opts.allOrganizations
|
|
59
54
|
}, ask, out);
|
|
60
55
|
finish(0);
|
|
61
56
|
});
|
|
62
|
-
users.command("set-role").description("Change a user's role, or several comma separated (refuses to demote the last admin)").argument("<email>").argument("<role>").action(async (email, role) => {
|
|
57
|
+
pinOptions(users.command("set-role").description("Change a user's role, or several comma separated (refuses to demote the last admin)")).argument("<email>").argument("<role>").action(async (email, role, opts) => {
|
|
63
58
|
const { setRoleCommand } = await import("./manage.js");
|
|
64
59
|
await setRoleCommand(await projectApi(), {
|
|
65
60
|
email,
|
|
66
|
-
role
|
|
61
|
+
role,
|
|
62
|
+
organization: opts.organization,
|
|
63
|
+
allOrganizations: opts.allOrganizations
|
|
67
64
|
}, out);
|
|
68
65
|
finish(0);
|
|
69
66
|
});
|
|
70
|
-
for (const disabled of [true, false]) users.command(disabled ? "disable" : "enable").description(disabled ? "Ban a user and revoke their sessions" : "Lift a ban").argument("<email>").action(async (email) => {
|
|
67
|
+
for (const disabled of [true, false]) pinOptions(users.command(disabled ? "disable" : "enable").description(disabled ? "Ban a user and revoke their sessions" : "Lift a ban")).argument("<email>").action(async (email, opts) => {
|
|
71
68
|
const { setDisabledInProject } = await import("./set-disabled.js");
|
|
72
|
-
|
|
69
|
+
const { loadProjectModules } = await import("./load-auth.js");
|
|
70
|
+
await setDisabledInProject(await loadAuth(), await loadProjectModules(process.cwd()), {
|
|
73
71
|
email,
|
|
74
|
-
disabled
|
|
72
|
+
disabled,
|
|
73
|
+
organization: opts.organization,
|
|
74
|
+
allOrganizations: opts.allOrganizations
|
|
75
75
|
}, out);
|
|
76
76
|
finish(0);
|
|
77
77
|
});
|
|
@@ -80,9 +80,12 @@ const registerUsers = (program) => {
|
|
|
80
80
|
await listRolesCommand(await projectApi(), out);
|
|
81
81
|
finish(0);
|
|
82
82
|
});
|
|
83
|
-
users.command("list").description("List users: email, role, creation date").action(async () => {
|
|
83
|
+
pinOptions(users.command("list").description("List users: email, role, creation date; with organizations, the members of the organization")).action(async (opts) => {
|
|
84
84
|
const { listUsersCommand } = await import("./commands.js");
|
|
85
|
-
await listUsersCommand(await projectApi(),
|
|
85
|
+
await listUsersCommand(await projectApi(), {
|
|
86
|
+
organization: opts.organization,
|
|
87
|
+
allOrganizations: opts.allOrganizations
|
|
88
|
+
}, out);
|
|
86
89
|
finish(0);
|
|
87
90
|
});
|
|
88
91
|
};
|
|
@@ -2,9 +2,10 @@ import { protobaseVersion } from "../version/version.js";
|
|
|
2
2
|
import { usersApi } from "./users-api.js";
|
|
3
3
|
import { setDisabledCommand } from "./manage.js";
|
|
4
4
|
import { checkMigrationRecord } from "@protobase/server";
|
|
5
|
+
import { plainStoreDb, runtimeModel } from "@protobase/server/internal";
|
|
5
6
|
//#region src/users/set-disabled.ts
|
|
6
|
-
const setDisabledInProject = async (auth, options, out) => {
|
|
7
|
-
await checkMigrationRecord(auth, protobaseVersion);
|
|
7
|
+
const setDisabledInProject = async (auth, modules, options, out) => {
|
|
8
|
+
await checkMigrationRecord(plainStoreDb(auth), runtimeModel(auth, modules), protobaseVersion);
|
|
8
9
|
await setDisabledCommand(usersApi(auth), options, out);
|
|
9
10
|
};
|
|
10
11
|
//#endregion
|
package/dist/users/users-api.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pinSource } from "../organizations/pin-source.js";
|
|
2
|
+
import { addMember, createUser, deleteUser, hasUsers, listUsers, roleChoices, setUserBanned, setUserRole } from "@protobase/server";
|
|
2
3
|
//#region src/users/users-api.ts
|
|
3
4
|
const usersApi = (auth) => ({
|
|
5
|
+
...pinSource(auth),
|
|
4
6
|
hasUsers: () => hasUsers(auth),
|
|
5
7
|
roles: async () => ({
|
|
6
8
|
roles: roleChoices(auth),
|
|
@@ -8,10 +10,14 @@ const usersApi = (auth) => ({
|
|
|
8
10
|
labels: auth.roleDefinitions.labels
|
|
9
11
|
}),
|
|
10
12
|
createUser: (input) => createUser(auth, input),
|
|
11
|
-
listUsers: (after) => listUsers(auth,
|
|
13
|
+
listUsers: (scope, after) => listUsers(auth, {
|
|
14
|
+
...after && { after },
|
|
15
|
+
...scope !== void 0 && { scope }
|
|
16
|
+
}),
|
|
12
17
|
deleteUser: (email) => deleteUser(auth, email),
|
|
13
18
|
setUserRole: (input) => setUserRole(auth, input),
|
|
14
|
-
setUserBanned: (input) => setUserBanned(auth, input)
|
|
19
|
+
setUserBanned: (input) => setUserBanned(auth, input),
|
|
20
|
+
addMember: (input) => addMember(auth, input)
|
|
15
21
|
});
|
|
16
22
|
//#endregion
|
|
17
23
|
export { usersApi };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { protobaseVersion } from "../version/version.js";
|
|
1
2
|
import { buildProject } from "../config/build-project.js";
|
|
3
|
+
import { builtRuntimeModel } from "../config/project-modules.js";
|
|
2
4
|
import { openAppDatabase } from "../project/pg-db.js";
|
|
3
5
|
import { projectAdmin } from "../project/project-admin.js";
|
|
4
6
|
import { readManifest } from "../bundle/manifest.js";
|
|
@@ -7,7 +9,7 @@ import { loadBundle } from "../serve/load-bundle.js";
|
|
|
7
9
|
import { statSync } from "node:fs";
|
|
8
10
|
import path from "node:path";
|
|
9
11
|
import pg from "pg";
|
|
10
|
-
import {
|
|
12
|
+
import { checkMigrationRecord, configExports, hasBuckets, isCaptured, startJobs } from "@protobase/server";
|
|
11
13
|
//#region src/worker/start-worker.ts
|
|
12
14
|
const bundleConfigFile = async (bundle) => {
|
|
13
15
|
if (!statSync(bundle).isDirectory()) return bundle;
|
|
@@ -15,8 +17,8 @@ const bundleConfigFile = async (bundle) => {
|
|
|
15
17
|
};
|
|
16
18
|
/**
|
|
17
19
|
* Runs the project's jobs, and nothing else, until `stop`: the same handlers `protobase serve` runs, in a process of
|
|
18
|
-
* their own, built from the config the same way. It reads the
|
|
19
|
-
*
|
|
20
|
+
* their own, built from the config the same way. It reads the record of migrations at start and refuses a database
|
|
21
|
+
* the app would not start on, like `serve`.
|
|
20
22
|
*/
|
|
21
23
|
const startWorker = async ({ config, databaseUrl, openDb = (url) => openAppDatabase(pg, url) }) => {
|
|
22
24
|
if (!databaseUrl) throw new Error("No database: set DATABASE_URL");
|
|
@@ -30,11 +32,12 @@ const startWorker = async ({ config, databaseUrl, openDb = (url) => openAppDatab
|
|
|
30
32
|
});
|
|
31
33
|
if (project.jobs.length === 0 && !builtIn) throw new Error("The bundle has no jobs: name their module in protobase.config.ts as `jobs`, or give a resource events, history, comments or an AI field, or declare a time rollup");
|
|
32
34
|
const { admin, jobs: definitions } = projectAdmin(project, db);
|
|
33
|
-
await
|
|
35
|
+
await checkMigrationRecord(db, builtRuntimeModel(project), protobaseVersion);
|
|
34
36
|
return {
|
|
35
37
|
definitions,
|
|
36
38
|
runtime: await startJobs({
|
|
37
39
|
db,
|
|
40
|
+
scope: await admin.organizationScope(),
|
|
38
41
|
jobs: definitions,
|
|
39
42
|
decryptField: admin.decryptField,
|
|
40
43
|
...project.mailer && { mailer: project.mailer },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.130.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.130.0",
|
|
47
|
+
"@protobase/layout": "0.130.0",
|
|
48
|
+
"@protobase/query": "0.130.0",
|
|
49
|
+
"@protobase/schema": "0.130.0",
|
|
50
|
+
"@protobase/server": "0.130.0",
|
|
51
|
+
"@protobase/ui": "0.130.0",
|
|
52
|
+
"@protobase/workflows": "0.130.0",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -14,4 +14,5 @@ Endpoints of your own beside the REST API.
|
|
|
14
14
|
- [Calling a function](../guides/api-functions.md#calling-a-function): The typed client's `invoke` calls a function with the signed-in user's token, from an action or any page.
|
|
15
15
|
- [Work after the response](../guides/api-functions.md#work-after-the-response): A function can answer at once and finish its work afterwards, which a graceful stop waits for.
|
|
16
16
|
- [Hono apps](../guides/api-functions.md#hono-apps): A function with several routes can be a Hono app.
|
|
17
|
+
- [The organization's tables](../guides/api-functions.md#the-organizations-tables) (beta): With organizations on, the `db` of functions, jobs and hooks, and sign-in's own queries, read and write the memberships, invitations and personal access tokens of one organization only, the caller's, and with organizations off after being on, the default organization's, unless the code opts out with `db.unscoped('<reason>')`; raw SQL names those tables through `scoped()` or `unscoped()`.
|
|
17
18
|
- [Long queries](../guides/api-functions.md#long-queries): A function or job that does bulk work may run queries for up to 30 seconds, on a connection kept for it, and functions and jobs always leave a connection to page requests.
|
|
@@ -12,8 +12,8 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
12
12
|
- [Project scripts](../reference/cli.md#run): `protobase run` runs a seed or a migration script on the CLI's packages.
|
|
13
13
|
- [Migrate command](../reference/cli.md#migrate): `protobase migrate` applies the project's SQL migrations, with nothing installed, and `--plan` prints the SQL it would apply.
|
|
14
14
|
- [Migrations from config](../reference/cli.md#migration): Writes the SQL migrations for what the config turns on, as files of the project.
|
|
15
|
-
- [Schema snapshot](../reference/cli.md#migration) (beta): `protobase.snapshot.json` in the project describes the schema its migrations make, so each new migration is the next numbered file and the change shows in review. The sign-in tables are worked out from it without a database, `protobase migration check` fails CI when the config has a change the migrations lack,
|
|
16
|
-
- [User and organization commands](../reference/cli.md#users): Create users, set roles and manage organizations from the terminal.
|
|
15
|
+
- [Schema snapshot](../reference/cli.md#migration) (beta): `protobase.snapshot.json` in the project describes the schema its migrations make, so each new migration is the next numbered file and the change shows in review. The sign-in tables and every built-in schema are worked out from it without a database, `protobase migration check` fails CI when the config has a change the migrations lack, `drop` takes the newest file back, and `protobase migration baseline` starts the snapshot of an existing app from its database, or records the built-in schemas an earlier version made, once, without changing or dropping anything.
|
|
16
|
+
- [User and organization commands](../reference/cli.md#users): Create users, set roles and manage organizations from the terminal, in the organization the config pins, another one you name, or every one when you ask.
|
|
17
17
|
- [Encryption commands](../reference/cli.md#encryption-status): Report and fix plaintext or old-key values of encrypted fields.
|
|
18
18
|
- [One bundle](../reference/cli.md#build): `protobase build` writes one folder with everything the app needs, without a database or secrets. It fails on a view that filters, sorts or searches by a field its resource does not allow.
|
|
19
19
|
- [Source maps](../reference/cli.md#source-maps): The bundle and plugins can carry source maps with debug ids, for an error tracker to read browser stack frames.
|
|
@@ -23,6 +23,7 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
23
23
|
- [Host module list](../reference/cli.md#the-config-module): Each release of `@protobase/cli` carries the modules its runtime supplies to a bundle as `@protobase/cli/host-modules.json`, for a host to check a bundle's imports against the version that serves it.
|
|
24
24
|
- [Migrations at update time](../guides/deploy.md#migrations): The bundle carries the project's migrations, and the runtime applies them before the new version serves, in batches of one transaction each, refusing a second run while one runs, with an `.after.sql` beside a file for statements such as `create index concurrently`, which a stopped run's next run finishes.
|
|
25
25
|
- [Migration record](../guides/deploy.md#the-record-of-migrations): Every migration file Protobase writes ends by adding its own row to `migrations.history`, so any tool that applies the file also records it. At startup the server reads the record: it starts when the database matches its version or is ahead only by additive migrations, and when the database is behind, it refuses and says what is missing and how to fix it.
|
|
26
|
+
- [Changes that break older code](../reference/cli.md#changes-that-break-older-code) (beta): `protobase migration` applies each new file to the database in a transaction it rolls back and names what the code still running would lose; Protobase's own parts keep what older code reads, a change only a hand-written file can make is refused with the way through, and a file that breaks older code makes the version before it refuse to start, saying rolling back is blocked. `protobase migration check` lints hand-written files with Postgres's own parser and warns of statements that lock reads.
|
|
26
27
|
- [Release steps](../reference/cli.md#release-steps): `protobase-serve migrate-release` brings a database up to a release's own built-in schema steps straight from a built bundle, with a dry-run plan, without writing files into the project.
|
|
27
28
|
- [Single-file runtime](../reference/cli.md#build-serve): The runtime as one file, so a host needs only Bun and that file.
|
|
28
29
|
- [Separate worker](../reference/cli.md#worker): Jobs and event delivery in their own process.
|
|
@@ -8,7 +8,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
8
8
|
- [Sign-in page](../reference/client.md#the-admin-app): The app signs people in at its own address, where the browser's Back returns to the step before, and signing in comes back to the page they were on.
|
|
9
9
|
- [First admin](../reference/auth.md#first-run): No account can be made over the web while the app has no users. You create the first admin from the terminal, and the last active admin cannot be deleted, demoted or blocked.
|
|
10
10
|
- [Users from a script](../reference/auth.md#first-run): A seed or another script of the project creates and lists users, and mints their tokens, on the app's own sign-in.
|
|
11
|
-
- [Versioned sign-in tables](../reference/auth.md#migrations): The sign-in tables come from numbered steps that ship with Protobase, a chain for each module of sign-in, written as the project's own migrations and recorded in the database, so a deploy checks them without comparing tables. Every step only adds, and one that assumes something of the rows already there checks it first and names the rows to fix.
|
|
11
|
+
- [Versioned sign-in tables](../reference/auth.md#migrations): The sign-in tables come from numbered steps that ship with Protobase, a chain for each module of sign-in, written as the project's own migrations and recorded in the database, so a deploy checks them without comparing tables. Every step only adds, and one that assumes something of the rows already there checks it first and names the rows to fix. A feature's tables exist only once the config turns it on, and turning it on is the next migration. Turning it off keeps its tables and rows, and the columns it adds to other tables, counting by hour the writes older code still makes to them, and turning it on again goes on from them, refusing while they hold rows unless `protobase migrate --force` brings them back. Archiving or deleting them is coming soon.
|
|
12
12
|
- [Table and column names](../reference/auth.md#table-and-column-names): Every sign-in table can take another name or a prefix, and every column but `id` another name, from the config, and the migrations, sign-in and Protobase's own queries all use it.
|
|
13
13
|
- [Existing users table](../reference/auth.md#an-existing-users-table): Sign-in can use the users table another system keeps in the same database.
|
|
14
14
|
- [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
|
|
@@ -39,6 +39,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
39
39
|
- [Staff sign-in](../reference/auth.md#staff-sign-in): The team that runs an app signs in as a person to help them, with a reason and a log entry.
|
|
40
40
|
- [Roles](../reference/auth.md#roles): A user holds one or more roles and switches between them without signing in again.
|
|
41
41
|
- [Organizations](../reference/auth.md#organizations): People work in one organization at a time, see only its records, and are invited with their own roles.
|
|
42
|
+
- [The default organization](../reference/auth.md#the-default-organization) (beta): Turning organizations on makes the default organization your config names, with every existing user its member in the role you choose, and every personal access token working in it; turning them off keeps every row, and until they are turned back on, only members of the default organization can sign in and use their tokens.
|
|
42
43
|
- [First organization](../reference/auth.md#first-organization-and-start-address) (beta): People outside any organization name their first one, called by your app's word such as workspace, in one step, or join one they are invited to, and land on the start address your app sets. The screen says what it is doing while it creates or joins, and lets them try again after a network failure.
|
|
43
44
|
- [Status](../reference/status.md) (beta): People set themselves busy or do not disturb, with a text of their own such as "Having lunch" and a time it clears, from the user menu; the people they share an organization with see it beside their name, with your app's online or away mark on the members page and in the sidebar.
|
|
44
45
|
- [API tokens](../reference/auth.md#tokens-and-roles): A signed-in session gets short-lived tokens for the API.
|
|
@@ -48,7 +48,7 @@ The second argument of a handler (`c.env` in a [Hono app](#hono-apps)):
|
|
|
48
48
|
| --- | --- |
|
|
49
49
|
| `session` | The caller: `{ user: { id, roles }, tenant? }`, from the app's `authenticate`. |
|
|
50
50
|
| `records` | The app's resources, acting as the caller: `list`, `get`, `create`, `update`, `delete`, `softDeleteField`. |
|
|
51
|
-
| `db` | The Kysely instance itself. It skips every access rule, row filter and tenant scope. |
|
|
51
|
+
| `db` | The Kysely instance itself. It skips every access rule, row filter and the tenant scope of `.tenant` resources, but keeps the [organization's tables](#the-organizations-tables) to the caller's organization. |
|
|
52
52
|
| `caller()` | Resolves to `{ session, records }`. Public functions use it to ask for a caller when they need one. |
|
|
53
53
|
| `decryptField(resource, key, field)` | An [encrypted field](../reference/data-config.md#reading-in-jobs-and-functions)'s value, skipping access rules like `db`; each read is audited, naming the function and the caller. |
|
|
54
54
|
| `acceptWebSocket(events)` | Answers a WebSocket upgrade with a socket; return its response. See [WebSockets](#websockets). |
|
|
@@ -58,6 +58,31 @@ The second argument of a handler (`c.env` in a [Hono app](#hono-apps)):
|
|
|
58
58
|
|
|
59
59
|
A [public function](#public-functions-and-webhooks) has only `db`, `caller()`, `acceptWebSocket`, `calls`, `channels` and `name`.
|
|
60
60
|
|
|
61
|
+
### The organization's tables
|
|
62
|
+
|
|
63
|
+
:::caution[Beta]
|
|
64
|
+
The host commands read every organization, and no check in CI finds raw SQL that names these tables as plain text. Sign-in's own queries keep to one organization (see [the reference](../reference/auth.md#organizations)).
|
|
65
|
+
:::
|
|
66
|
+
|
|
67
|
+
With [organizations](../reference/auth.md#organizations) on, the tables of the auth store whose rows each belong to one organization, `member`, `invitation` and `personal_access_token` under the names the app gives them, show `db` only the caller's organization, the one their session works in. While organizations are off after being on, the tables they left show `db` only [the default organization](../reference/auth.md#the-default-organization), for a session of it, whose tenant is its id; a session of another tenant, or of none, sees none of their rows. A read, update or delete of one gets `organization_id = <the organization>` in the select, update or delete that reads the table: in its `where`, or for a joined table in the join's `on`, so a `left join` keeps its other rows. Subqueries, common table expressions and `exists` filter their own tables, and a name a common table expression takes is not the table. An insert writes the organization, and one naming another organization, or an update moving a row to one, is refused with a `ScopeRefused` error before it reaches the database; so is an upsert's update of a row of another organization, which it leaves as it is. A table of the project's own with the same name in another schema is never taken for the store's. A right or full join, or a `merge`, of one of these tables throws, as the scope cannot keep it to the organization.
|
|
68
|
+
|
|
69
|
+
A [job](../reference/jobs.md) works in the organization of the `db` that enqueued it, such as a function's. A public function, a function called at `/api/sb/functions/v1`, a webhook's call of a function, a recurring job, and a job enqueued with `db.unscoped(...)`, a plain database or from SQL work in no organization: their `db` reads no row of these tables and writes none. Work that means every organization's rows says so, with a reason for whoever reviews it:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const everyone = await db.unscoped('the nightly report counts members of every organization').selectFrom('auth.member').select(({ fn }) => fn.countAll().as('members')).executeTakeFirstOrThrow()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Raw SQL names these tables through `scoped(table)` for the organization's rows, or `unscoped(reason, table)` for every organization's, both from `@protobase/query`. Naming one with `sql.table` or `sql.id` is refused, and `db.withoutPlugins()` too, as it would drop the scope without a reason:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { scoped } from '@protobase/query'
|
|
79
|
+
import { sql } from 'kysely'
|
|
80
|
+
|
|
81
|
+
const { rows } = await sql`select count(*) as members from ${scoped('auth.member')} as m`.execute(db)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`scoped(table)` runs only on a database that keeps the scope: elsewhere Postgres refuses it as an unknown function. SQL written as plain text, `sql.raw`, a database view, or Kysely's `CompiledQuery.raw` is not seen, so name these tables through the helpers. The `.tenant` resources of the app's own tables are not kept to the organization in `db`: their API and `records` are.
|
|
85
|
+
|
|
61
86
|
## Reading and writing records as the caller
|
|
62
87
|
|
|
63
88
|
```ts title="functions/ready-for-pickup.ts"
|
|
@@ -131,7 +156,7 @@ export default defineFunction({ public: true }, async (request, { db }) => {
|
|
|
131
156
|
- `verifyStandardWebhook(request, { secret })` checks [Standard Webhooks](https://www.standardwebhooks.com) signatures, as Supabase Auth hooks, Svix and Resend send them, including the timestamp (5 minutes of tolerance by default).
|
|
132
157
|
- Stripe ships its own check: `stripe.webhooks.constructEventAsync(await request.text(), request.headers.get('stripe-signature'), secret)`.
|
|
133
158
|
|
|
134
|
-
A public function has no caller, so it has no `records`. Its `db` skips the tenant scope too, so filter by tenant yourself where it matters. When a function should serve anyone but treat a signed-in caller differently, `await context.caller()` resolves the caller from the request, or rejects with the `401` problem.
|
|
159
|
+
A public function has no caller, so it has no `records`. Its `db` skips the tenant scope too, so filter by tenant yourself where it matters, and it sees no row of the [organization's tables](#the-organizations-tables). When a function should serve anyone but treat a signed-in caller differently, `await context.caller()` resolves the caller from the request, or rejects with the `401` problem.
|
|
135
160
|
|
|
136
161
|
## WebSockets
|
|
137
162
|
|
|
@@ -40,13 +40,13 @@ Every migration Protobase writes ends with the statement that records it in `mig
|
|
|
40
40
|
|
|
41
41
|
A file may have an `.after.sql` beside it, such as `007_indexes.after.sql` beside `007_indexes.sql`, for statements that cannot run in a transaction, such as `create index concurrently if not exists`. `migrate` runs it once the file's batch commits, one statement at a time, each ending with a semicolon at the end of a line, then marks the file complete. A run that stops before then, killed or failing, leaves the file applied but not complete, and the next `migrate` finishes it first; an index it left invalid is dropped and built again. A project's own runner skips `.after.sql` files.
|
|
42
42
|
|
|
43
|
-
The server reads the
|
|
43
|
+
The server reads the record once at startup, with the model it builds from the config and its code: the sign-in store with sign-in on, and each built-in schema that is a module with numbered steps, such as the [jobs schema](../reference/jobs.md#the-jobs-schema), when the app needs it. It compares each part on its own, leaving out a part of the record it does not read, such as a schema a newer version needs, and starts when a row records every part as it reads it and no migration after that row is not additive, as when a deploy is rolled back to the version before. It refuses when the database lacks something it reads or has it at an older step, naming the sign-in module or the schema and its step, the version the database matches and its own, and the two ways out: `protobase migrate --plan` and `protobase migrate`, or running the version the database matches:
|
|
44
44
|
|
|
45
45
|
```
|
|
46
46
|
The database is behind Protobase 0.128.0, so the server will not start: the auth store's passkeys module is at step 1 (passkeys), and this version needs step 2 (rp_id_index). To bring the database up to 0.128.0, run `protobase migrate --plan` to see the migrations it will apply, then `protobase migrate`. Or run Protobase 0.127.5, the version the database matches.
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
It refuses as well on a database ahead of it by a migration that is not additive, while a unique index of an `.after.sql` is still building, and on a database
|
|
49
|
+
It refuses as well on a database ahead of it by a migration that is not additive after the newest one recording the model it reads, saying that rolling back to it is blocked and naming the version the database matches, while a unique index of an `.after.sql` is still building, and on a database that records no migration while the app reads the sign-in store or a schema module, such as one migrated before this record: `protobase auth migration` then writes the file that records the store, and [`protobase migration baseline`](../reference/cli.md#migration) the one that records a schema an earlier version's migration made. An unfinished plain index does not keep it from starting. The server never migrates the database itself, and never turns a feature off because its tables are missing. Besides the record, with the built-in assistant it checks what the database has given the [query role](../reference/assistant.md#the-built-in-backend), which a migration cannot promise. <gap>A migration that breaks older code without changing the model the record holds, such as a hand-written rename of a resource's column, cannot stop the version before from starting because recording the app's own release in `migrations.history` is not implemented.</gap> <gap>An app's CI cannot run its previous release's tests against the new schema because the older-code test is not implemented.</gap>
|
|
50
50
|
|
|
51
51
|
## Images
|
|
52
52
|
|
|
@@ -66,7 +66,7 @@ It lives at `/api/assistant` on the app's own origin and answers with the user's
|
|
|
66
66
|
|
|
67
67
|
Both run **outside Protobase's access rules and tenant scoping**: whoever has the `admin` or `ai` role can read every resource's table, and with approval change everything the app's database role can, since `propose_write_query` still runs as that role. Give the app a database role without superuser rights, and those roles only to people who may see all of the data.
|
|
68
68
|
|
|
69
|
-
Making the query role needs `CREATEROLE` once, for the role that applies the migrations; that role becomes a member of it and may run the function. The query role bypasses row-level security only when the migrating role may grant that, a superuser or, on Postgres 16 and later, a role with `BYPASSRLS`; otherwise it reads what the tables' policies give it. When the app serves as another database role than the one that migrates, grant that role `usage on schema query` and `execute on function query.run_read_only(text, integer)`. `protobase migration` writes the role only when it finds the built-in assistant's key, `PROTOBASE_ASSISTANT_API_KEY` in the `.env` it reads or `assistant.apiKey` of the config, so run it with the key set even when only production has the real one. The server does not start while the role
|
|
69
|
+
Making the query role needs `CREATEROLE` once, for the role that applies the migrations; that role becomes a member of it and may run the function. The query role bypasses row-level security only when the migrating role may grant that, a superuser or, on Postgres 16 and later, a role with `BYPASSRLS`; otherwise it reads what the tables' policies give it. When the app serves as another database role than the one that migrates, grant that role `usage on schema query` and `execute on function query.run_read_only(text, integer)`. `protobase migration` writes the role only when it finds the built-in assistant's key, `PROTOBASE_ASSISTANT_API_KEY` in the `.env` it reads or `assistant.apiKey` of the config, so run it with the key set even when only production has the real one. The server does not start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks the role, its function or a resource's grants, while the role can read an auth table, or while it may call a `SECURITY DEFINER` function, other than a trigger function, whose owner can read one: the statement would read the auth store through it, so revoke `execute` on such a function from `PUBLIC`, or keep it in a schema without a resource. Adding a resource writes its grants into the next migration, and removing one takes them back.
|
|
70
70
|
|
|
71
71
|
### The app's own tools
|
|
72
72
|
|