From b6efbb03560c7108f01801e6b0c2bd90656370e2 Mon Sep 17 00:00:00 2001 From: wangxiaoxian <1094175543@qq.com> Date: Mon, 9 Mar 2026 00:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=9D=83=E9=99=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/sync-db.js | 17 ---- sync-db.js | 235 ---------------------------------------------- 2 files changed, 252 deletions(-) delete mode 100644 config/sync-db.js delete mode 100644 sync-db.js diff --git a/config/sync-db.js b/config/sync-db.js deleted file mode 100644 index 131fd77..0000000 --- a/config/sync-db.js +++ /dev/null @@ -1,17 +0,0 @@ -const sequelize = require('./db'); -const { Region, Apartment, Room, Rental } = require('../models'); - -// 同步数据库表结构 -const syncDatabase = async () => { - try { - console.log('正在同步数据库表结构...'); - await sequelize.sync({ force: true }); - console.log('数据库表结构同步成功'); - } catch (error) { - console.error('数据库表结构同步失败:', error); - } finally { - await sequelize.close(); - } -}; - -syncDatabase(); \ No newline at end of file diff --git a/sync-db.js b/sync-db.js deleted file mode 100644 index bcb7cd3..0000000 --- a/sync-db.js +++ /dev/null @@ -1,235 +0,0 @@ -const sequelize = require('./config/db'); -const { DataTypes } = require('sequelize'); - -// 定义 WaterBill 模型 -const WaterBill = sequelize.define('WaterBill', { - id: { - type: DataTypes.INTEGER, - primaryKey: true, - autoIncrement: true - }, - roomId: { - type: DataTypes.INTEGER, - allowNull: false, - references: { - model: 'rooms', - key: 'id' - } - }, - startDate: { - type: DataTypes.DATE, - allowNull: false - }, - endDate: { - type: DataTypes.DATE, - allowNull: true - }, - startReading: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - endReading: { - type: DataTypes.DECIMAL(10, 2), - allowNull: true - }, - usage: { - type: DataTypes.DECIMAL(10, 2), - allowNull: true - }, - unitPrice: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - amount: { - type: DataTypes.DECIMAL(10, 2), - allowNull: true - }, - status: { - type: DataTypes.ENUM('unbilled', 'unpaid', 'paid'), - allowNull: false, - defaultValue: 'unpaid' - }, - createTime: { - type: DataTypes.DATE, - defaultValue: DataTypes.NOW - }, - updateTime: { - type: DataTypes.DATE, - defaultValue: DataTypes.NOW, - onUpdate: DataTypes.NOW - }, - isDeleted: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: 0 - } -}, { - tableName: 'water_bills', - timestamps: false -}); - -// 定义 ElectricityBill 模型 -const ElectricityBill = sequelize.define('ElectricityBill', { - id: { - type: DataTypes.INTEGER, - primaryKey: true, - autoIncrement: true - }, - roomId: { - type: DataTypes.INTEGER, - allowNull: false, - references: { - model: 'rooms', - key: 'id' - } - }, - startDate: { - type: DataTypes.DATE, - allowNull: false - }, - endDate: { - type: DataTypes.DATE, - allowNull: false - }, - startReading: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - endReading: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - usage: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - unitPrice: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - amount: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - status: { - type: DataTypes.ENUM('unpaid', 'paid'), - allowNull: false, - defaultValue: 'unpaid' - }, - createTime: { - type: DataTypes.DATE, - defaultValue: DataTypes.NOW - }, - updateTime: { - type: DataTypes.DATE, - defaultValue: DataTypes.NOW, - onUpdate: DataTypes.NOW - }, - isDeleted: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: 0 - } -}, { - tableName: 'electricity_bills', - timestamps: false -}); - -// 定义 Rental 模型 -const Rental = sequelize.define('Rental', { - id: { - type: DataTypes.INTEGER, - primaryKey: true, - autoIncrement: true - }, - roomId: { - type: DataTypes.INTEGER, - allowNull: false, - references: { - model: 'rooms', - key: 'id' - } - }, - tenantId: { - type: DataTypes.INTEGER, - allowNull: false, - references: { - model: 'tenants', - key: 'id' - } - }, - contractId: { - type: DataTypes.INTEGER, - allowNull: false, - references: { - model: 'contracts', - key: 'id' - } - }, - startDate: { - type: DataTypes.DATE, - allowNull: false - }, - endDate: { - type: DataTypes.DATE, - allowNull: false - }, - rent: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - deposit: { - type: DataTypes.DECIMAL(10, 2), - allowNull: false - }, - status: { - type: DataTypes.ENUM('active', 'expired'), - allowNull: false, - defaultValue: 'active' - }, - remark: { - type: DataTypes.TEXT, - allowNull: true - }, - createTime: { - type: DataTypes.DATE, - defaultValue: DataTypes.NOW - }, - updateTime: { - type: DataTypes.DATE, - defaultValue: DataTypes.NOW, - onUpdate: DataTypes.NOW - }, - isDeleted: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: 0 - } -}, { - tableName: 'rentals', - timestamps: false -}); - -// 同步数据库模型 -async function syncDatabase() { - try { - console.log('开始同步数据库模型...'); - // 同步 Rental 模型 - await Rental.sync({ alter: true }); - console.log('Rental 模型同步成功'); - // 同步 WaterBill 模型 - await WaterBill.sync({ alter: true }); - console.log('WaterBill 模型同步成功'); - // 同步 ElectricityBill 模型 - await ElectricityBill.sync({ alter: true }); - console.log('ElectricityBill 模型同步成功'); - console.log('数据库模型同步成功'); - process.exit(0); - } catch (error) { - console.error('数据库模型同步失败:', error); - process.exit(1); - } -} - -// 执行同步 -syncDatabase();