rentease-backend/update_room_price_fields.sql

16 lines
633 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 更新房间表结构,将原来的 price 字段改为 monthlyPrice 和 yearlyPrice 两个字段
-- 添加 monthlyPrice 字段
ALTER TABLE rooms ADD COLUMN monthlyPrice DECIMAL(10, 2) NOT NULL DEFAULT 0 AFTER area;
-- 添加 yearlyPrice 字段
ALTER TABLE rooms ADD COLUMN yearlyPrice DECIMAL(10, 2) NOT NULL DEFAULT 0 AFTER monthlyPrice;
-- 将原来的 price 字段值复制到 monthlyPrice 字段
UPDATE rooms SET monthlyPrice = price;
-- 计算年租金并更新 yearlyPrice 字段(月租金 * 12
UPDATE rooms SET yearlyPrice = monthlyPrice * 12;
-- 删除原来的 price 字段
ALTER TABLE rooms DROP COLUMN price;