feat(database): initialize database schema and triggers
- Created initial database schema with tables for Users, Roles, Products, and related entities. - Added foreign key constraints to maintain data integrity across tables. - Implemented triggers for managing stock movements on insert, update, and delete operations. - Developed scripts to dump existing triggers and pull trigger definitions from the database.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import 'dotenv/config'
|
||||
import mysql from 'mysql2/promise'
|
||||
import { env } from 'prisma/config'
|
||||
;(async () => {
|
||||
const db = await mysql.createConnection({
|
||||
host: env('DATABASE_HOST'),
|
||||
user: env('DATABASE_USER'),
|
||||
password: env('DATABASE_PASSWORD'),
|
||||
database: env('DATABASE_NAME'),
|
||||
port: Number(env('DATABASE_PORT')) || 3306,
|
||||
})
|
||||
|
||||
const [rows] = await db.query(`
|
||||
SELECT
|
||||
TRIGGER_NAME,
|
||||
ACTION_STATEMENT
|
||||
FROM INFORMATION_SCHEMA.TRIGGERS
|
||||
WHERE TRIGGER_SCHEMA = DATABASE();
|
||||
`)
|
||||
|
||||
console.log(rows)
|
||||
|
||||
await db.end()
|
||||
})()
|
||||
Reference in New Issue
Block a user