Skip to content

Commit 796c7ca

Browse files
authored
Merge pull request #1620 from running-elephant/dev
Sync Dev into Master
2 parents a8228e4 + eee0cfa commit 796c7ca

File tree

8 files changed

+43
-17
lines changed

8 files changed

+43
-17
lines changed

bin/h2/datart.demo.mv.db

-24 KB
Binary file not shown.

config/profiles/application-config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ server:
8080
keyAlias: tomcat
8181

8282
datart:
83+
migration:
84+
enable: true # 是否开启数据库自动升级
8385
server:
8486
address: ${datart.address:http://127.0.0.1:8080}
8587

data-providers/data-provider-base/src/main/java/datart/data/provider/calcite/dialect/CustomSqlDialect.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ private static Context createContext(JdbcDriverInfo driverInfo) {
5656
public void unparseOffsetFetch(SqlWriter writer, SqlNode offset, SqlNode fetch) {
5757
if (driverInfo.getSupportSqlLimit() != null && driverInfo.getSupportSqlLimit()) {
5858
unparseFetchUsingLimit(writer, offset, fetch);
59+
} else {
60+
super.unparseOffsetFetch(writer, offset, fetch);
5961
}
60-
super.unparseOffsetFetch(writer, offset, fetch);
6162
}
6263
}

data-providers/jdbc-data-provider/src/test/java/datart/data/provider/sql/SqlScriptRenderTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
3737
import org.apache.calcite.sql.parser.SqlParseException;
3838
import org.apache.calcite.sql.parser.SqlParserPos;
39+
import org.junit.jupiter.api.Disabled;
3940
import org.junit.jupiter.api.Test;
4041
import org.springframework.boot.test.context.SpringBootTest;
4142

4243
import java.util.List;
4344

4445
@SpringBootTest(classes = DataProviderTestApplication.class)
4546
@Slf4j
47+
@Disabled
4648
public class SqlScriptRenderTest {
4749

4850
private static final String T = "DATART_VTABLE";

server/src/main/java/datart/server/config/CustomPropertiesValidate.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.springframework.core.env.MutablePropertySources;
1515
import org.springframework.core.env.PropertiesPropertySource;
1616
import org.springframework.core.env.PropertySource;
17+
import org.springframework.core.io.ClassPathResource;
1718
import org.springframework.core.io.FileSystemResource;
1819
import org.springframework.data.util.ReflectionUtils;
1920

@@ -101,21 +102,42 @@ private String getConfigName(Class clazz, String fieldName) {
101102
}
102103

103104
private void switchProfile(ConfigurableEnvironment environment) {
104-
String url = getDefaultDBUrl(environment);
105-
if (url == null || (url.contains("null") && environment.getProperty(CONFIG_DATABASE_URL) == null)) {
106-
environment.setActiveProfiles("demo");
107-
System.err.println("【********* Invalid database configuration. Datart is running in demo mode *********】");
105+
try {
106+
String url = getDefaultDBUrl(environment);
107+
if (url == null || (url.contains("null") && environment.getProperty(CONFIG_DATABASE_URL) == null)) {
108+
environment.setActiveProfiles("demo");
109+
// remove default config propertySource
110+
String defaultConfig = null;
111+
for (PropertySource<?> propertySource : environment.getPropertySources()) {
112+
if (propertySource.getName().contains("application-config")) {
113+
defaultConfig = propertySource.getName();
114+
}
115+
}
116+
if (defaultConfig != null) {
117+
environment.getPropertySources().remove(defaultConfig);
118+
}
119+
// add demo propertySource
120+
List<PropertySource<?>> propertySources = new YamlPropertySourceLoader().load("demo", new ClassPathResource("application-demo.yml"));
121+
if (propertySources != null && propertySources.size() > 0) {
122+
for (PropertySource<?> propertySource : propertySources) {
123+
environment.getPropertySources().addFirst(propertySource);
124+
}
125+
}
126+
System.err.println("【********* Invalid database configuration. Datart is running in demo mode *********】");
127+
}
128+
} catch (Exception e) {
129+
throw new RuntimeException(e);
108130
}
109131
}
110132

111-
private String processDBUrl(ConfigurableEnvironment environment){
133+
private String processDBUrl(ConfigurableEnvironment environment) {
112134
String jdbcUrl = environment.getProperty(DATABASE_URL);
113135
if (!StringUtils.startsWith(jdbcUrl, "jdbc:mysql")) {
114136
return "";
115137
}
116138
Boolean isModify = false;
117139
String[] split = StringUtils.split(jdbcUrl, "?");
118-
if (split.length>1) {
140+
if (split.length > 1) {
119141
Map<String, Object> urlParams = UrlUtils.getParamsMap(split[1]);
120142
if (!"true".equals(urlParams.getOrDefault("allowMultiQueries", "false"))) {
121143
isModify = true;
@@ -128,7 +150,7 @@ private String processDBUrl(ConfigurableEnvironment environment){
128150
jdbcUrl = split[0] + "?" + UrlUtils.covertMapToUrlParams(urlParams);
129151
} else {
130152
isModify = true;
131-
jdbcUrl = jdbcUrl+"?allowMultiQueries=true&characterEncoding=utf-8";
153+
jdbcUrl = jdbcUrl + "?allowMultiQueries=true&characterEncoding=utf-8";
132154
}
133155
if (isModify) {
134156
return jdbcUrl;
@@ -148,7 +170,7 @@ private String getDefaultDBUrl(ConfigurableEnvironment environment) {
148170
System.err.println("Default config application-config not found ");
149171
return null;
150172
}
151-
return (String) propertySources.get(0).getProperty(DATABASE_URL);
173+
return environment.getProperty(DATABASE_URL);
152174
} catch (Exception e) {
153175
e.printStackTrace();
154176
System.err.println("Default config application-config not found ");

server/src/main/java/datart/server/config/DatabaseMigrationAware.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import datart.core.migration.DatabaseMigration;
2222
import lombok.extern.slf4j.Slf4j;
2323
import org.springframework.beans.BeansException;
24-
import org.springframework.beans.factory.annotation.Value;
2524
import org.springframework.context.ApplicationContext;
2625
import org.springframework.context.ApplicationContextAware;
2726
import org.springframework.core.Ordered;
@@ -31,12 +30,10 @@
3130
@Component
3231
public class DatabaseMigrationAware implements ApplicationContextAware, Ordered {
3332

34-
@Value("${datart.migration.enable:true}")
35-
private boolean migrationEnable;
36-
3733
@Override
3834
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
39-
if (!migrationEnable) {
35+
String migrationEnable = applicationContext.getEnvironment().getProperty("datart.migration.enable");
36+
if (migrationEnable == null || "false".equals(migrationEnable)) {
4037
return;
4138
}
4239
DatabaseMigration databaseMigration = applicationContext.getBean(DatabaseMigration.class);
@@ -51,4 +48,5 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
5148
public int getOrder() {
5249
return 0;
5350
}
51+
5452
}

server/src/main/resources/application-demo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ server:
1515
mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/css,image/*
1616

1717
datart:
18+
1819
migration:
1920
enable: false
2021

server/src/main/resources/application.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ shiro:
6868
enabled: false
6969

7070
datart:
71+
migration:
72+
enable: false
73+
7174
server:
7275
path-prefix: /api/v1
7376

74-
migration:
75-
enable: true
76-
7777
server:
7878
port: 8080
7979
address: 0.0.0.0

0 commit comments

Comments
 (0)