Added auth functionality, initial work with views and field types
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
exports.up = function (knex) {
|
||||
return knex.schema
|
||||
.createTable('users', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('email', 255).notNullable();
|
||||
table.string('password', 255).notNullable();
|
||||
table.string('firstName', 255);
|
||||
table.string('lastName', 255);
|
||||
table.boolean('isActive').defaultTo(true);
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.unique(['email']);
|
||||
table.index(['email']);
|
||||
})
|
||||
.createTable('roles', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('name', 255).notNullable();
|
||||
table.string('guardName', 255).defaultTo('api');
|
||||
table.text('description');
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.unique(['name', 'guardName']);
|
||||
})
|
||||
.createTable('permissions', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('name', 255).notNullable();
|
||||
table.string('guardName', 255).defaultTo('api');
|
||||
table.text('description');
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.unique(['name', 'guardName']);
|
||||
})
|
||||
.createTable('role_permissions', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.uuid('roleId').notNullable();
|
||||
table.uuid('permissionId').notNullable();
|
||||
table.timestamps(true, true);
|
||||
|
||||
table
|
||||
.foreign('roleId')
|
||||
.references('id')
|
||||
.inTable('roles')
|
||||
.onDelete('CASCADE');
|
||||
table
|
||||
.foreign('permissionId')
|
||||
.references('id')
|
||||
.inTable('permissions')
|
||||
.onDelete('CASCADE');
|
||||
table.unique(['roleId', 'permissionId']);
|
||||
})
|
||||
.createTable('user_roles', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.uuid('userId').notNullable();
|
||||
table.uuid('roleId').notNullable();
|
||||
table.timestamps(true, true);
|
||||
|
||||
table
|
||||
.foreign('userId')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('CASCADE');
|
||||
table
|
||||
.foreign('roleId')
|
||||
.references('id')
|
||||
.inTable('roles')
|
||||
.onDelete('CASCADE');
|
||||
table.unique(['userId', 'roleId']);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function (knex) {
|
||||
return knex.schema
|
||||
.dropTableIfExists('user_roles')
|
||||
.dropTableIfExists('role_permissions')
|
||||
.dropTableIfExists('permissions')
|
||||
.dropTableIfExists('roles')
|
||||
.dropTableIfExists('users');
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
exports.up = function (knex) {
|
||||
return knex.schema
|
||||
.createTable('object_definitions', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('apiName', 255).notNullable().unique();
|
||||
table.string('label', 255).notNullable();
|
||||
table.string('pluralLabel', 255);
|
||||
table.text('description');
|
||||
table.boolean('isSystem').defaultTo(false);
|
||||
table.boolean('isCustom').defaultTo(true);
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.index(['apiName']);
|
||||
})
|
||||
.createTable('field_definitions', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.uuid('objectDefinitionId').notNullable();
|
||||
table.string('apiName', 255).notNullable();
|
||||
table.string('label', 255).notNullable();
|
||||
table.string('type', 50).notNullable(); // String, Number, Date, Boolean, Reference, etc.
|
||||
table.integer('length');
|
||||
table.integer('precision');
|
||||
table.integer('scale');
|
||||
table.string('referenceObject', 255);
|
||||
table.text('defaultValue');
|
||||
table.text('description');
|
||||
table.boolean('isRequired').defaultTo(false);
|
||||
table.boolean('isUnique').defaultTo(false);
|
||||
table.boolean('isSystem').defaultTo(false);
|
||||
table.boolean('isCustom').defaultTo(true);
|
||||
table.integer('displayOrder').defaultTo(0);
|
||||
table.timestamps(true, true);
|
||||
|
||||
table
|
||||
.foreign('objectDefinitionId')
|
||||
.references('id')
|
||||
.inTable('object_definitions')
|
||||
.onDelete('CASCADE');
|
||||
table.unique(['objectDefinitionId', 'apiName']);
|
||||
table.index(['objectDefinitionId']);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function (knex) {
|
||||
return knex.schema
|
||||
.dropTableIfExists('field_definitions')
|
||||
.dropTableIfExists('object_definitions');
|
||||
};
|
||||
35
backend/migrations/tenant/20250126000003_create_apps.js
Normal file
35
backend/migrations/tenant/20250126000003_create_apps.js
Normal file
@@ -0,0 +1,35 @@
|
||||
exports.up = function (knex) {
|
||||
return knex.schema
|
||||
.createTable('apps', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('slug', 255).notNullable().unique();
|
||||
table.string('label', 255).notNullable();
|
||||
table.text('description');
|
||||
table.integer('display_order').defaultTo(0);
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.index(['slug']);
|
||||
})
|
||||
.createTable('app_pages', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.uuid('app_id').notNullable();
|
||||
table.string('slug', 255).notNullable();
|
||||
table.string('label', 255).notNullable();
|
||||
table.string('type', 50).notNullable(); // List, Detail, Custom
|
||||
table.string('object_api_name', 255);
|
||||
table.integer('display_order').defaultTo(0);
|
||||
table.timestamps(true, true);
|
||||
|
||||
table
|
||||
.foreign('app_id')
|
||||
.references('id')
|
||||
.inTable('apps')
|
||||
.onDelete('CASCADE');
|
||||
table.unique(['app_id', 'slug']);
|
||||
table.index(['app_id']);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function (knex) {
|
||||
return knex.schema.dropTableIfExists('app_pages').dropTableIfExists('apps');
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
exports.up = async function (knex) {
|
||||
// Create standard Account object
|
||||
await knex.schema.createTable('accounts', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('name', 255).notNullable();
|
||||
table.string('website', 255);
|
||||
table.string('phone', 50);
|
||||
table.string('industry', 100);
|
||||
table.uuid('ownerId');
|
||||
table.timestamps(true, true);
|
||||
|
||||
table
|
||||
.foreign('ownerId')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('SET NULL');
|
||||
table.index(['name']);
|
||||
table.index(['ownerId']);
|
||||
});
|
||||
|
||||
// Insert Account object definition
|
||||
const [objectId] = await knex('object_definitions').insert({
|
||||
id: knex.raw('(UUID())'),
|
||||
apiName: 'Account',
|
||||
label: 'Account',
|
||||
pluralLabel: 'Accounts',
|
||||
description: 'Standard Account object',
|
||||
isSystem: true,
|
||||
isCustom: false,
|
||||
created_at: knex.fn.now(),
|
||||
updated_at: knex.fn.now(),
|
||||
});
|
||||
|
||||
// Insert Account field definitions
|
||||
const objectDefId =
|
||||
objectId ||
|
||||
(await knex('object_definitions').where('apiName', 'Account').first()).id;
|
||||
|
||||
await knex('field_definitions').insert([
|
||||
{
|
||||
id: knex.raw('(UUID())'),
|
||||
objectDefinitionId: objectDefId,
|
||||
apiName: 'name',
|
||||
label: 'Account Name',
|
||||
type: 'String',
|
||||
length: 255,
|
||||
isRequired: true,
|
||||
isSystem: true,
|
||||
isCustom: false,
|
||||
displayOrder: 1,
|
||||
created_at: knex.fn.now(),
|
||||
updated_at: knex.fn.now(),
|
||||
},
|
||||
{
|
||||
id: knex.raw('(UUID())'),
|
||||
objectDefinitionId: objectDefId,
|
||||
apiName: 'website',
|
||||
label: 'Website',
|
||||
type: 'String',
|
||||
length: 255,
|
||||
isSystem: true,
|
||||
isCustom: false,
|
||||
displayOrder: 2,
|
||||
created_at: knex.fn.now(),
|
||||
updated_at: knex.fn.now(),
|
||||
},
|
||||
{
|
||||
id: knex.raw('(UUID())'),
|
||||
objectDefinitionId: objectDefId,
|
||||
apiName: 'phone',
|
||||
label: 'Phone',
|
||||
type: 'String',
|
||||
length: 50,
|
||||
isSystem: true,
|
||||
isCustom: false,
|
||||
displayOrder: 3,
|
||||
created_at: knex.fn.now(),
|
||||
updated_at: knex.fn.now(),
|
||||
},
|
||||
{
|
||||
id: knex.raw('(UUID())'),
|
||||
objectDefinitionId: objectDefId,
|
||||
apiName: 'industry',
|
||||
label: 'Industry',
|
||||
type: 'String',
|
||||
length: 100,
|
||||
isSystem: true,
|
||||
isCustom: false,
|
||||
displayOrder: 4,
|
||||
created_at: knex.fn.now(),
|
||||
updated_at: knex.fn.now(),
|
||||
},
|
||||
{
|
||||
id: knex.raw('(UUID())'),
|
||||
objectDefinitionId: objectDefId,
|
||||
apiName: 'ownerId',
|
||||
label: 'Owner',
|
||||
type: 'Reference',
|
||||
referenceObject: 'User',
|
||||
isSystem: true,
|
||||
isCustom: false,
|
||||
displayOrder: 5,
|
||||
created_at: knex.fn.now(),
|
||||
updated_at: knex.fn.now(),
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
exports.down = function (knex) {
|
||||
return knex.schema.dropTableIfExists('accounts');
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.up = function(knex) {
|
||||
return knex.schema.table('field_definitions', (table) => {
|
||||
table.jsonb('ui_metadata').nullable().comment('JSON metadata for UI rendering including display options, validation rules, and field-specific configurations');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.down = function(knex) {
|
||||
return knex.schema.table('field_definitions', (table) => {
|
||||
table.dropColumn('ui_metadata');
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user