mirror of
https://github.com/vran-dev/databasir.git
synced 2025-08-08 18:10:26 +08:00
feature: support database, schema config (#44)
* feat: add schema_name * feat: support database, schema config * feat: add more detail info in databaseTypes * feat: add permission control to databaseType api * feat: update frontend resources
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.databasir.core.domain.database.data;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DatabaseTypeSimpleResponse {
|
||||
|
||||
private String databaseType;
|
||||
|
||||
private String description;
|
||||
|
||||
private String urlPattern;
|
||||
|
||||
private String jdbcProtocol;
|
||||
}
|
@@ -89,10 +89,17 @@ public class DatabaseTypeService {
|
||||
});
|
||||
}
|
||||
|
||||
public List<String> listSimpleDatabaseTypes() {
|
||||
public List<DatabaseTypeSimpleResponse> listSimpleDatabaseTypes() {
|
||||
return databaseTypeDao.selectAll()
|
||||
.stream()
|
||||
.map(DatabaseTypePojo::getDatabaseType)
|
||||
.map(type -> {
|
||||
DatabaseTypeSimpleResponse response = new DatabaseTypeSimpleResponse();
|
||||
response.setDatabaseType(type.getDatabaseType());
|
||||
response.setUrlPattern(type.getUrlPattern());
|
||||
response.setDescription(type.getDescription());
|
||||
response.setJdbcProtocol(type.getJdbcProtocol());
|
||||
return response;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
|
||||
public interface DocumentPojoConverter extends BaseConverter {
|
||||
|
||||
@Mapping(target = "databaseName", source = "meta.databaseName")
|
||||
@Mapping(target = "schemaName", source = "meta.schemaName")
|
||||
@Mapping(target = "isArchive", constant = "false")
|
||||
DatabaseDocumentPojo toDatabasePojo(Integer projectId,
|
||||
com.databasir.core.meta.data.DatabaseMeta meta,
|
||||
|
@@ -19,6 +19,8 @@ public class DatabaseDocumentResponse {
|
||||
|
||||
private String databaseName;
|
||||
|
||||
private String schemaName;
|
||||
|
||||
private String productName;
|
||||
|
||||
private String productVersion;
|
||||
|
@@ -13,6 +13,8 @@ public class DatabaseDocumentSimpleResponse {
|
||||
|
||||
private String databaseName;
|
||||
|
||||
private String schemaName;
|
||||
|
||||
private String productName;
|
||||
|
||||
private String productVersion;
|
||||
|
@@ -89,7 +89,7 @@ public class DocumentService {
|
||||
databasirConfig.setIgnoreTableNameRegex(jsonConverter.fromJson(rule.getIgnoreTableNameRegexArray()));
|
||||
databasirConfig.setIgnoreTableColumnNameRegex(jsonConverter.fromJson(rule.getIgnoreColumnNameRegexArray()));
|
||||
return Databasir.of(databasirConfig)
|
||||
.get(jdbcConnection, dataSource.getDatabaseName())
|
||||
.get(jdbcConnection, dataSource.getDatabaseName(), dataSource.getSchemaName())
|
||||
.orElseThrow(DomainErrors.DATABASE_META_NOT_FOUND::exception);
|
||||
}
|
||||
|
||||
|
@@ -40,6 +40,9 @@ public class ProjectCreateRequest {
|
||||
@NotBlank
|
||||
private String databaseName;
|
||||
|
||||
@NotBlank
|
||||
private String schemaName;
|
||||
|
||||
@NotBlank
|
||||
private String databaseType;
|
||||
|
||||
|
@@ -34,6 +34,8 @@ public class ProjectDetailResponse {
|
||||
|
||||
private String databaseName;
|
||||
|
||||
private String schemaName;
|
||||
|
||||
private String databaseType;
|
||||
|
||||
private List<DataSourcePropertyValue> properties = new ArrayList<>();
|
||||
|
@@ -15,6 +15,8 @@ public class ProjectListCondition {
|
||||
|
||||
private String databaseNameContains;
|
||||
|
||||
private String schemaNameContains;
|
||||
|
||||
private String databaseType;
|
||||
|
||||
private Integer groupId;
|
||||
@@ -29,6 +31,10 @@ public class ProjectListCondition {
|
||||
Condition condition = Tables.DATA_SOURCE.DATABASE_NAME.contains(databaseNameContains);
|
||||
conditions.add(condition);
|
||||
}
|
||||
if (schemaNameContains != null) {
|
||||
Condition condition = Tables.DATA_SOURCE.SCHEMA_NAME.contains(schemaNameContains);
|
||||
conditions.add(condition);
|
||||
}
|
||||
if (databaseType != null) {
|
||||
Condition condition = Tables.DATA_SOURCE.DATABASE_TYPE.eq(databaseType);
|
||||
conditions.add(condition);
|
||||
|
@@ -15,6 +15,8 @@ public class ProjectSimpleResponse {
|
||||
|
||||
private String databaseName;
|
||||
|
||||
private String schemaName;
|
||||
|
||||
private String databaseType;
|
||||
|
||||
private Boolean isAutoSync;
|
||||
|
@@ -22,6 +22,9 @@ public class ProjectTestConnectionRequest {
|
||||
@NotBlank
|
||||
private String databaseName;
|
||||
|
||||
@NotBlank
|
||||
private String schemaName;
|
||||
|
||||
@NotBlank
|
||||
private String databaseType;
|
||||
|
||||
|
@@ -39,6 +39,9 @@ public class ProjectUpdateRequest {
|
||||
@NotBlank
|
||||
private String databaseName;
|
||||
|
||||
@NotBlank
|
||||
private String schemaName;
|
||||
|
||||
@NotBlank
|
||||
private String databaseType;
|
||||
|
||||
|
@@ -169,6 +169,7 @@ public class ProjectService {
|
||||
password,
|
||||
request.getUrl(),
|
||||
request.getDatabaseName(),
|
||||
request.getSchemaName(),
|
||||
request.getDatabaseType(),
|
||||
properties);
|
||||
}
|
||||
|
@@ -78,7 +78,8 @@ public class CustomDatabaseConnectionFactory implements DatabaseConnectionFactor
|
||||
String urlPattern = type.getUrlPattern();
|
||||
String jdbcUrl = urlPattern.replace("{{jdbc.protocol}}", type.getJdbcProtocol())
|
||||
.replace("{{db.url}}", context.getUrl())
|
||||
.replace("{{db.name}}", context.getSchema());
|
||||
.replace("{{db.name}}", context.getDatabaseName())
|
||||
.replace("{{db.schema}}", context.getSchemaName());
|
||||
Properties info = new Properties();
|
||||
info.put("user", context.getUsername());
|
||||
info.put("password", context.getPassword());
|
||||
|
@@ -25,7 +25,9 @@ public interface DatabaseConnectionFactory {
|
||||
|
||||
private String url;
|
||||
|
||||
private String schema;
|
||||
private String databaseName;
|
||||
|
||||
private String schemaName;
|
||||
|
||||
private Properties properties;
|
||||
}
|
||||
|
@@ -36,7 +36,8 @@ public class DatabaseConnectionService {
|
||||
.username(username)
|
||||
.password(password)
|
||||
.url(url)
|
||||
.schema(dataSource.getDatabaseName())
|
||||
.databaseName(dataSource.getDatabaseName())
|
||||
.schemaName(dataSource.getSchemaName())
|
||||
.properties(info)
|
||||
.databaseType(dataSource.getDatabaseType())
|
||||
.build();
|
||||
@@ -54,6 +55,7 @@ public class DatabaseConnectionService {
|
||||
String password,
|
||||
String url,
|
||||
String databaseName,
|
||||
String schemaName,
|
||||
String databaseType,
|
||||
Properties properties) {
|
||||
try {
|
||||
@@ -61,7 +63,8 @@ public class DatabaseConnectionService {
|
||||
.username(username)
|
||||
.password(password)
|
||||
.url(url)
|
||||
.schema(databaseName)
|
||||
.databaseName(databaseName)
|
||||
.schemaName(schemaName)
|
||||
.properties(properties)
|
||||
.databaseType(databaseType)
|
||||
.build();
|
||||
|
@@ -29,7 +29,7 @@ public class MysqlDatabaseConnectionFactory implements DatabaseConnectionFactory
|
||||
info.put("user", context.getUsername());
|
||||
info.put("password", context.getPassword());
|
||||
info.putAll(context.getProperties());
|
||||
String jdbcUrl = "jdbc:mysql://" + context.getUrl() + "/" + context.getSchema();
|
||||
String jdbcUrl = "jdbc:mysql://" + context.getUrl() + "/" + context.getDatabaseName();
|
||||
return DriverManager.getConnection(jdbcUrl, info);
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,7 @@ public class PostgresqlDatabaseConnectionFactory implements DatabaseConnectionFa
|
||||
info.put("user", context.getUsername());
|
||||
info.put("password", context.getPassword());
|
||||
info.putAll(context.getProperties());
|
||||
String jdbcUrl = "jdbc:postgresql://" + context.getUrl() + "/" + context.getSchema();
|
||||
String jdbcUrl = "jdbc:postgresql://" + context.getUrl() + "/" + context.getDatabaseName();
|
||||
return DriverManager.getConnection(jdbcUrl, info);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user