invoice number
This commit is contained in:
@@ -732,67 +732,6 @@
|
|||||||
"foreignKeys": {},
|
"foreignKeys": {},
|
||||||
"nativeEnums": {}
|
"nativeEnums": {}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"columns": {
|
|
||||||
"phone": {
|
|
||||||
"name": "phone",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"unsigned": false,
|
|
||||||
"autoincrement": false,
|
|
||||||
"primary": false,
|
|
||||||
"nullable": false,
|
|
||||||
"length": 255,
|
|
||||||
"mappedType": "string"
|
|
||||||
},
|
|
||||||
"code": {
|
|
||||||
"name": "code",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"unsigned": false,
|
|
||||||
"autoincrement": false,
|
|
||||||
"primary": false,
|
|
||||||
"nullable": false,
|
|
||||||
"length": 255,
|
|
||||||
"mappedType": "string"
|
|
||||||
},
|
|
||||||
"expires_at": {
|
|
||||||
"name": "expires_at",
|
|
||||||
"type": "timestamptz",
|
|
||||||
"unsigned": false,
|
|
||||||
"autoincrement": false,
|
|
||||||
"primary": false,
|
|
||||||
"nullable": false,
|
|
||||||
"length": 6,
|
|
||||||
"mappedType": "datetime"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"name": "otp",
|
|
||||||
"schema": "public",
|
|
||||||
"indexes": [
|
|
||||||
{
|
|
||||||
"keyName": "otp_phone_index",
|
|
||||||
"columnNames": [
|
|
||||||
"phone"
|
|
||||||
],
|
|
||||||
"composite": false,
|
|
||||||
"constraint": false,
|
|
||||||
"primary": false,
|
|
||||||
"unique": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"keyName": "otp_pkey",
|
|
||||||
"columnNames": [
|
|
||||||
"phone"
|
|
||||||
],
|
|
||||||
"composite": false,
|
|
||||||
"constraint": true,
|
|
||||||
"primary": true,
|
|
||||||
"unique": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"checks": [],
|
|
||||||
"foreignKeys": {},
|
|
||||||
"nativeEnums": {}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"columns": {
|
"columns": {
|
||||||
"id": {
|
"id": {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { Migration } from '@mikro-orm/migrations';
|
||||||
|
|
||||||
|
export class Migration20260422123253 extends Migration {
|
||||||
|
|
||||||
|
override async up(): Promise<void> {
|
||||||
|
// Create sequence for invoice_number
|
||||||
|
this.addSql(`CREATE SEQUENCE IF NOT EXISTS invoice_number_seq START 1;`);
|
||||||
|
|
||||||
|
// Set the sequence to start from the max existing invoice_number + 1
|
||||||
|
this.addSql(`SELECT setval('invoice_number_seq', COALESCE((SELECT MAX(invoice_number) FROM invoices), 0) + 1, false);`);
|
||||||
|
|
||||||
|
// Set default value for invoice_number to use the sequence
|
||||||
|
this.addSql(`ALTER TABLE invoices ALTER COLUMN invoice_number SET DEFAULT nextval('invoice_number_seq');`);
|
||||||
|
}
|
||||||
|
|
||||||
|
override async down(): Promise<void> {
|
||||||
|
// Remove default from invoice_number
|
||||||
|
this.addSql(`ALTER TABLE invoices ALTER COLUMN invoice_number DROP DEFAULT;`);
|
||||||
|
|
||||||
|
// Drop the sequence
|
||||||
|
this.addSql(`DROP SEQUENCE IF EXISTS invoice_number_seq;`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user