項(xiàng)目有時(shí)候去要項(xiàng)目啟動(dòng)就生成數(shù)據(jù)庫(kù)表 或多人開(kāi)發(fā)維護(hù)版的時(shí)候 用這個(gè)比較方便管理
自己去找liquibase gva坐標(biāo)
package com.tlsq.service.flowable.config;
import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.database.DatabaseConnection;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.DatabaseException;
import liquibase.resource.ClassLoaderResourceAccessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
/**
* 配置類(注釋不想修改了 之前寫(xiě)工作流的)
* Flowable Data Extension Configuration.
* @author: Lu Yang
* @data: 2019-05-21 15:04
*/
@Configuration
public class DatabaseConfiguration {
// 表的開(kāi)頭命名
private static final String LIQUIBASE_CHANGELOG_PREFIX = "T_";
@Bean
public Liquibase liquibase(DataSource dataSource) {
Liquibase liquibase = null;
try {
DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
// 自己sql表腳本路徑
liquibase = new Liquibase("custom/flowable-extend.sql", new ClassLoaderResourceAccessor(), database);
liquibase.update("luyang");
return liquibase;
} catch (Exception e) {
throw new RuntimeException("Error creating liquibase database", e);
} finally {
closeDatabase(liquibase);
}
}
private void closeDatabase(Liquibase liquibase) {
if (liquibase != null) {
Database database = liquibase.getDatabase();
if (database != null) {
try {
database.close();
} catch (DatabaseException e) {
e.printStackTrace();
}
}
}
}
}
springboot 2.0以后在application.yml文件加上
spring:
liquibase:
enabled: false
--liquibase formatted sql
--changeset luyang:1
-- ----------------------------------------------------------
-- 用戶操作類型表 所用sql格式看著比xml舒服 給出格式自己去修改 一定要加上文件頭兩個(gè)申明注意不要有空格
-- ----------------------------------------------------------
drop table if exists `t_operation_type`;
create table `t_operation_type`
(
`id_` int(11) not null auto_increment comment '主鍵ID',
`type_` varchar(32) default null comment '動(dòng)作',
`valid_` bit(1) default b'0' comment '是否有效 0:是 1:否',
`create_time_` datetime default current_timestamp comment '創(chuàng)建時(shí)間',
primary key (`id_`)
) engine = innodb
auto_increment = 1
default charset = utf8mb4
collate utf8mb4_unicode_ci comment = '用戶操作類型表';
insert into t_operation_type (type_) values ('啟動(dòng)流程');
insert into t_operation_type (type_) values ('通過(guò)');
insert into t_operation_type (type_) values ('駁回');
insert into t_operation_type (type_) values ('終止');
-- 不允許用戶id_NAME映射表 用戶ID重復(fù)
alter table flowable.t_user_id_name add unique (user_id_);
https://gitee.com/cn-luyang/luyang-cloud.git
自己整了個(gè)項(xiàng)目蓖扑,期待小伙伴一起玩
歡迎大佬們提交PR
朋友們幫忙點(diǎn)個(gè)starter撬即,感謝了