Allow disabling schema auto generation #5063
Replies: 4 comments 2 replies
-
|
There is a config flag within the config/database.ts file and you may use it to disable schema generation https://lucid.adonisjs.com/docs/schema-classes#configuration |
Beta Was this translation helpful? Give feedback.
-
|
Just curious, I'm using the @column({
prepare: (value: Decimal | string | number) => {
if (value instanceof Decimal) {
return value.toString()
}
return value
},
consume: (value: string) => {
return new Decimal(value)
},
})
declare contributionAmount: DecimalWould be nice to generate some fields in the schema but not all fields. e,g ignore |
Beta Was this translation helpful? Give feedback.
-
|
You can already customize how those columns are generated using the For your example, I did something similar in one of my project. I have created the following custom decorator: import { column } from '@adonisjs/lucid/orm';
import { Decimal } from '#shared/utils/decimal';
/**
* Decorator for decimal columns that converts PostgreSQL decimal strings to Decimal objects.
* Uses our Decimal class (wrapping big.js) for precise decimal arithmetic.
*
* @param precision - Number of decimal places (default: 2)
*/
export function decimal(precision: number = 2) {
return function (target: any, propertyKey: string) {
const descriptor = {
consume: (value: string | number | null): Decimal | null => {
if (value === null || value === undefined) {
return null;
}
return new Decimal(value).round(precision);
},
prepare: (value: Decimal | number | null): string | null => {
if (value === null || value === undefined) {
return null;
}
if (value instanceof Decimal) {
return value.toFixed(precision);
}
return new Decimal(value).toFixed(precision);
},
};
column(descriptor)(target, propertyKey);
};
}and then defined the following rule: import type { SchemaRules } from '@adonisjs/lucid/types/schema_generator';
const schemaRules: SchemaRules = {
types: {
decimal: {
tsType: 'Decimal',
decorator: '@decimal()',
imports: [
{ source: '#shared/decorators/decimal', namedImports: ['decimal'] },
{ source: '#shared/utils/decimal', typeImports: ['Decimal'] },
],
},
},
};
export default schemaRules; |
Beta Was this translation helpful? Give feedback.
-
|
Awesome thanks both of those seem like great options! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have quite a few modifications that I apply to my models (custom ulid column decorator, using branded types, etc). This means my model ends up overriding ~half of the auto generated schema keys, which makes using the auto generated schemas feel unnecessary.
Beta Was this translation helpful? Give feedback.
All reactions