diff options
| author | haturatu <taro@eyes4you.org> | 2026-04-22 04:46:24 +0900 |
|---|---|---|
| committer | haturatu <taro@eyes4you.org> | 2026-04-22 04:46:24 +0900 |
| commit | 4b0271272e983fdb85d4b816cbd91f34d91a7884 (patch) | |
| tree | ad92ba661f0f9e8b16d93f333ebf43ffd331a892 /pb_migrations/1730000000_bootstrap.js | |
| parent | d18b4f9d615d8942ff604a53be92da2c8e853635 (diff) | |
Diffstat (limited to 'pb_migrations/1730000000_bootstrap.js')
| -rw-r--r-- | pb_migrations/1730000000_bootstrap.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/pb_migrations/1730000000_bootstrap.js b/pb_migrations/1730000000_bootstrap.js new file mode 100644 index 0000000..3a4bfca --- /dev/null +++ b/pb_migrations/1730000000_bootstrap.js @@ -0,0 +1,86 @@ +migrate((app) => { + let superusers = app.findCollectionByNameOrId("_superusers") + + let superuser = new Record(superusers) + superuser.set("email", "admin@example.com") + superuser.set("password", "change-me-now") + app.save(superuser) + + let users = new Collection({ + type: "auth", + name: "proxy_users", + listRule: null, + viewRule: null, + createRule: "", + updateRule: "@request.auth.id = id", + deleteRule: null, + fields: [ + { + name: "username", + type: "text", + required: true, + presentable: true, + min: 3, + max: 64, + pattern: "^[a-zA-Z0-9_.-]+$", + }, + { + name: "role", + type: "select", + required: true, + maxSelect: 1, + values: ["user", "admin"], + }, + { + name: "is_active", + type: "bool", + }, + { + name: "failed_logins", + type: "number", + onlyInt: true, + min: 0, + }, + { + name: "last_login_at", + type: "date", + }, + ], + indexes: [ + "CREATE UNIQUE INDEX idx_proxy_users_username ON proxy_users (username)", + ], + passwordAuth: { + enabled: true, + identityFields: ["username", "email"], + }, + }) + app.save(users) + + let usersCollection = app.findCollectionByNameOrId("proxy_users") + let admin = new Record(usersCollection) + admin.set("username", "admin") + admin.set("email", "proxy-admin@example.com") + admin.set("password", "password123") + admin.set("passwordConfirm", "password123") + admin.set("verified", true) + admin.set("emailVisibility", false) + admin.set("role", "admin") + admin.set("is_active", true) + admin.set("failed_logins", 0) + app.save(admin) +}, (app) => { + try { + let adminRecord = app.findAuthRecordByEmail("proxy_users", "proxy-admin@example.com") + app.delete(adminRecord) + } catch (_) {} + + try { + let usersCollection = app.findCollectionByNameOrId("proxy_users") + app.delete(usersCollection) + } catch (_) {} + + try { + let superuser = app.findAuthRecordByEmail("_superusers", "admin@example.com") + app.delete(superuser) + } catch (_) {} +}) |
