initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
//
|
||||
// M10 — Add role, shopUserId, and displayName to the users collection.
|
||||
//
|
||||
// This enables the RBX (Role-Based Experience). The `role` field determines
|
||||
// which dashboard and pages the user sees. `shopUserId` links a technician
|
||||
// account to its shop owner. `displayName` is a friendly name shown in the
|
||||
// technician profile and advisor assignment views.
|
||||
//
|
||||
|
||||
migrate(
|
||||
(db) => {
|
||||
const col = db.findCollectionByNameOrId('users');
|
||||
if (!col) {
|
||||
console.warn('[M10] users collection not found — skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
// ── role: select ────────────────────────────────────────────────────────
|
||||
const existingRole = col.fields.find((f) => f.name === 'role');
|
||||
if (!existingRole) {
|
||||
const f = new SelectField({
|
||||
name: 'role',
|
||||
required: false,
|
||||
values: ['advisor', 'technician', 'mobile'],
|
||||
maxSelect: 1,
|
||||
});
|
||||
col.fields.add(f);
|
||||
console.log('[M10] added role field to users');
|
||||
} else {
|
||||
console.log('[M10] role already exists — no change');
|
||||
}
|
||||
|
||||
// ── shopUserId: text (relation to the shop-owner user) ─────────────────
|
||||
const existingShopUser = col.fields.find((f) => f.name === 'shopUserId');
|
||||
if (!existingShopUser) {
|
||||
const f = new TextField({
|
||||
name: 'shopUserId',
|
||||
required: false,
|
||||
});
|
||||
col.fields.add(f);
|
||||
console.log('[M10] added shopUserId field to users');
|
||||
} else {
|
||||
console.log('[M10] shopUserId already exists — no change');
|
||||
}
|
||||
|
||||
// ── displayName: text ──────────────────────────────────────────────────
|
||||
const existingDisplayName = col.fields.find((f) => f.name === 'displayName');
|
||||
if (!existingDisplayName) {
|
||||
const f = new TextField({
|
||||
name: 'displayName',
|
||||
required: false,
|
||||
});
|
||||
col.fields.add(f);
|
||||
console.log('[M10] added displayName field to users');
|
||||
} else {
|
||||
console.log('[M10] displayName already exists — no change');
|
||||
}
|
||||
|
||||
db.save(col);
|
||||
},
|
||||
(db) => {
|
||||
const col = db.findCollectionByNameOrId('users');
|
||||
if (!col) return;
|
||||
col.fields.remove('role');
|
||||
col.fields.remove('shopUserId');
|
||||
col.fields.remove('displayName');
|
||||
db.save(col);
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user