fix(db): align migrations with entity model and idempotency
This commit is contained in:
@@ -3,6 +3,7 @@ package com.sino.mci.config;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -12,11 +13,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class FlywayConfig {
|
||||
|
||||
@Bean(initMethod = "migrate")
|
||||
public Flyway flyway(DataSource dataSource) {
|
||||
public Flyway flyway(
|
||||
DataSource dataSource,
|
||||
@Value("${spring.flyway.locations:classpath:db/migration}") String[] locations,
|
||||
@Value("${spring.flyway.baseline-on-migrate:true}") boolean baselineOnMigrate) {
|
||||
return Flyway.configure()
|
||||
.dataSource(dataSource)
|
||||
.locations("classpath:db/migration")
|
||||
.baselineOnMigrate(true)
|
||||
.locations(locations)
|
||||
.baselineOnMigrate(baselineOnMigrate)
|
||||
.load();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ CREATE TABLE IF NOT EXISTS mci_platform_role (
|
||||
role_name VARCHAR(128) NOT NULL COMMENT '角色名称',
|
||||
permissions JSON COMMENT '权限列表',
|
||||
status TINYINT NOT NULL DEFAULT 1,
|
||||
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='平台角色表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS mci_user (
|
||||
@@ -41,3 +42,7 @@ CREATE TABLE IF NOT EXISTS mci_user_role (
|
||||
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uk_user_role (user_id, role_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户角色关系表';
|
||||
|
||||
ALTER TABLE mci_user_role
|
||||
ADD CONSTRAINT fk_user_role_user_id FOREIGN KEY (user_id) REFERENCES mci_user (id),
|
||||
ADD CONSTRAINT fk_user_role_role_id FOREIGN KEY (role_id) REFERENCES mci_platform_role (id);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
INSERT INTO mci_platform_role (role_code, role_name, permissions) VALUES
|
||||
INSERT IGNORE INTO mci_platform_role (role_code, role_name, permissions) VALUES
|
||||
('admin', '租户管理员', '["*"]'),
|
||||
('operator', '运营操作员', '["send:write", "channel:read", "channel:write", "record:read"]'),
|
||||
('viewer', '只读用户', '["record:read", "channel:read"]');
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -24,4 +25,7 @@ public abstract class BaseEntity implements Serializable {
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user