diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ConfigServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ConfigServiceImpl.java index a7d383008..1ebe3757e 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ConfigServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ConfigServiceImpl.java @@ -9,7 +9,6 @@ import ai.chat2db.server.domain.core.converter.ConfigConverter; import ai.chat2db.server.domain.repository.Dbutils; import ai.chat2db.server.domain.repository.entity.SystemConfigDO; -import ai.chat2db.server.domain.repository.mapper.ChartMapper; import ai.chat2db.server.domain.repository.mapper.SystemConfigMapper; import ai.chat2db.server.tools.base.wrapper.result.ActionResult; import ai.chat2db.server.tools.base.wrapper.result.DataResult; diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceAccessBusinessServiceTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceAccessBusinessServiceTest.java new file mode 100644 index 000000000..4c0643bba --- /dev/null +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceAccessBusinessServiceTest.java @@ -0,0 +1,62 @@ +package ai.chat2db.server.start.test.core; + +import ai.chat2db.server.domain.api.model.DataSource; +import ai.chat2db.server.domain.api.service.DataSourceAccessBusinessService; +import ai.chat2db.server.domain.repository.Dbutils; +import ai.chat2db.server.start.test.TestApplication; +import ai.chat2db.server.tools.base.wrapper.result.ActionResult; +import ai.chat2db.server.tools.common.model.Context; +import ai.chat2db.server.tools.common.model.LoginUser; +import ai.chat2db.server.tools.common.util.ContextUtils; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DataSourceAccessBusinessServiceTest extends TestApplication { + + @Autowired + private DataSourceAccessBusinessService dataSourceAccessBusinessService; + + /** + * 1. First, determine whether it is a private data source (PRIVATE) based on the type of the data source. + * If it is a private data source, determine whether the currently logged-in user is the owner of the data source. + * If so, allow the operation, otherwise throw a permission exception. + *

+ * 2. If the currently logged-in user is an administrator userLoginIdentity(true, **), the operation is allowed. + * If the currently logged-in user is a common user, determine whether the user has permission to access the data source. + * If so, the operation is allowed. + *

+ * 3. If the team to which the currently logged-in user belongs has permission to access the data source, the operation is allowed. + *

+ * 4. If none of the above conditions are met, a permission exception is thrown. + */ + @Test + public void testCheckPermission() { +// userLoginIdentity(false, 3L); + userLoginIdentity(true, 2L); + + DataSource source = new DataSource(); +// source.setKind("PRIVATE"); + source.setKind("SHARED"); + source.setUserId(5L); + source.setId(3L); + + ActionResult actionResult = dataSourceAccessBusinessService.checkPermission(source); + assertNotNull(actionResult); + } + + /** + * Save the current user identity (administrator or normal user) and user ID to the context and database session for subsequent use. + * + * @param isAdmin + * @param userId + */ + private static void userLoginIdentity(boolean isAdmin, Long userId) { + Context context = Context.builder().loginUser( + LoginUser.builder().admin(isAdmin).id(userId).build() + ).build(); + ContextUtils.setContext(context); + Dbutils.setSession(); + } +} diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceAccessServiceTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceAccessServiceTest.java new file mode 100644 index 000000000..cc82ed378 --- /dev/null +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceAccessServiceTest.java @@ -0,0 +1,115 @@ +package ai.chat2db.server.start.test.core; + +import ai.chat2db.server.domain.api.model.DataSourceAccess; +import ai.chat2db.server.domain.api.param.datasource.DataSourceSelector; +import ai.chat2db.server.domain.api.param.datasource.access.DataSourceAccessComprehensivePageQueryParam; +import ai.chat2db.server.domain.api.param.datasource.access.DataSourceAccessCreatParam; +import ai.chat2db.server.domain.api.param.datasource.access.DataSourceAccessPageQueryParam; +import ai.chat2db.server.domain.api.param.datasource.access.DataSourceAccessSelector; +import ai.chat2db.server.domain.api.service.DataSourceAccessService; +import ai.chat2db.server.domain.repository.Dbutils; +import ai.chat2db.server.start.test.TestApplication; +import ai.chat2db.server.start.test.dialect.TestUtils; +import ai.chat2db.server.tools.base.wrapper.result.ActionResult; +import ai.chat2db.server.tools.base.wrapper.result.DataResult; +import ai.chat2db.server.tools.base.wrapper.result.PageResult; +import ai.chat2db.server.tools.common.model.Context; +import ai.chat2db.server.tools.common.model.LoginUser; +import ai.chat2db.server.tools.common.util.ContextUtils; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DataSourceAccessServiceTest extends TestApplication { + + @Autowired + private DataSourceAccessService dataSourceAccessService; + + @Test + public void testPageQuery() { +// userLoginIdentity(true,5L); + userLoginIdentity(false, 2L); + + + DataSourceAccessPageQueryParam queryParam = new DataSourceAccessPageQueryParam(); + queryParam.setDataSourceId(TestUtils.nextLong()); +// queryParam.setAccessObjectType("TEAM"); + queryParam.setAccessObjectType("USER"); + queryParam.setAccessObjectId(TestUtils.nextLong()); + queryParam.setPageNo(3); + queryParam.setPageSize(5); + + // Returns false by default + queryParam.setEnableReturnCount(true); + + + DataSourceAccessSelector accessSelector = new DataSourceAccessSelector(); + accessSelector.setAccessObject(true); + accessSelector.setDataSource(true); + accessSelector.setDataSourceSelector(new DataSourceSelector(true)); + + PageResult result = dataSourceAccessService.pageQuery(queryParam, accessSelector); + assertNotNull(result); + + } + + @Test + public void testComprehensivePageQuery() { + + userLoginIdentity(false, 2L); +// userLoginIdentity(true,5L); + + DataSourceAccessComprehensivePageQueryParam param = new DataSourceAccessComprehensivePageQueryParam(); + param.setPageNo(1); + param.setPageSize(10); + param.setEnableReturnCount(true); + param.setDataSourceId(TestUtils.nextLong()); + param.setAccessObjectType("USER"); +// param.setAccessObjectType("TEAM"); + param.setAccessObjectId(TestUtils.nextLong()); + param.setUserOrTeamSearchKey("test"); + param.setDataSourceSearchKey("m"); + + DataSourceAccessSelector selector = new DataSourceAccessSelector(); + selector.setAccessObject(true); + selector.setDataSource(true); + selector.setDataSourceSelector(new DataSourceSelector(true)); + + PageResult result = dataSourceAccessService.comprehensivePageQuery(param, selector); + assertNotNull(result); + } + + @Test + public void testCreateAndDelete() { + + userLoginIdentity(false, 8L); +// userLoginIdentity(true,6L); + + DataSourceAccessCreatParam creatParam = new DataSourceAccessCreatParam(); + creatParam.setDataSourceId(TestUtils.nextLong()); + creatParam.setAccessObjectId(TestUtils.nextLong()); + creatParam.setAccessObjectType("USER"); +// creatParam.setAccessObjectType("TEAM"); + + DataResult result = dataSourceAccessService.create(creatParam); + assertNotNull(result); + ActionResult delete = dataSourceAccessService.delete(result.getData()); + assertNotNull(delete); + + } + + /** + * Save the current user identity (administrator or normal user) and user ID to the context and database session for subsequent use. + * + * @param isAdmin + * @param userId + */ + private static void userLoginIdentity(boolean isAdmin, Long userId) { + Context context = Context.builder().loginUser( + LoginUser.builder().admin(isAdmin).id(userId).build() + ).build(); + ContextUtils.setContext(context); + Dbutils.setSession(); + } +} diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceServiceTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceServiceTest.java new file mode 100644 index 000000000..8adbfdb87 --- /dev/null +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DataSourceServiceTest.java @@ -0,0 +1,188 @@ +package ai.chat2db.server.start.test.core; + +import ai.chat2db.server.domain.api.model.DataSource; +import ai.chat2db.server.domain.api.param.datasource.*; +import ai.chat2db.server.domain.api.service.DataSourceService; +import ai.chat2db.server.domain.repository.Dbutils; +import ai.chat2db.server.start.test.TestApplication; +import ai.chat2db.server.start.test.dialect.DialectProperties; +import ai.chat2db.server.start.test.dialect.TestUtils; +import ai.chat2db.server.tools.base.wrapper.param.OrderBy; +import ai.chat2db.server.tools.base.wrapper.result.ActionResult; +import ai.chat2db.server.tools.base.wrapper.result.DataResult; +import ai.chat2db.server.tools.base.wrapper.result.ListResult; +import ai.chat2db.server.tools.base.wrapper.result.PageResult; +import ai.chat2db.server.tools.common.model.Context; +import ai.chat2db.server.tools.common.model.LoginUser; +import ai.chat2db.server.tools.common.util.ContextUtils; +import ai.chat2db.spi.config.DriverConfig; +import ai.chat2db.spi.model.Database; +import ai.chat2db.spi.model.KeyValue; +import ai.chat2db.spi.model.SSHInfo; +import ai.chat2db.spi.model.SSLInfo; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DataSourceServiceTest extends TestApplication { + + @Autowired + private DataSourceService dataSourceService; + + @Autowired + private List dialectPropertiesList; + + @Test + public void testCreateWithPermission() { +// userLoginIdentity(true, 1L); + userLoginIdentity(false, 2L); + + DataSourceCreateParam createParam = new DataSourceCreateParam(); + createParam.setKind("PRIVATE"); +// createParam.setKind("SHARED"); + createParam.setDriverConfig(new DriverConfig()); + + DataResult withPermission = dataSourceService.createWithPermission(createParam); + assertNotNull(withPermission.getData()); + + } + + @Test + public void testUpdateWithPermission() { +// userLoginIdentity(true, 7L); + userLoginIdentity(false, 2L); + + DataSourceUpdateParam updateParam = new DataSourceUpdateParam(); + updateParam.setId(4L); + updateParam.setDriverConfig(new DriverConfig()); + updateParam.setPassword("123456"); + + DataResult result = dataSourceService.updateWithPermission(updateParam); + ActionResult delete = dataSourceService.deleteWithPermission(4L); + assertNotNull(result.getData()); + assertNotNull(delete); + + } + + @Test + public void testQueryById() { + userLoginIdentity(false, 2L); +// userLoginIdentity(true, 7L); + + DataResult result = dataSourceService.queryById(3L); + ListResult dataSourceListResult = dataSourceService.listQuery(new ArrayList<>(), null); + assertNotNull(result.getData()); + assertNotNull(dataSourceListResult.getData()); + } + + @Test + public void testQueryExistent() { + userLoginIdentity(false, 2L); +// userLoginIdentity(true, 7L); + + DataSourceSelector selector = new DataSourceSelector(); + selector.setEnvironment(true); +// selector.setEnvironment(false); + + DataResult result = dataSourceService.queryExistent(3L, null); + assertNotNull( result.getData(),"Data should not be null"); + } + + @Test + public void testCopyByIdWithPermission() { + userLoginIdentity(false, 2L); +// userLoginIdentity(true, 7L); + + DataResult longDataResult = dataSourceService.copyByIdWithPermission(3L); + assertNotNull(longDataResult.getData()); + + } + + @Test + public void testQueryPage() { + userLoginIdentity(false,6L); +// userLoginIdentity(true,9L); + + DataSourcePageQueryParam queryParam = new DataSourcePageQueryParam(); + queryParam.setSearchKey("test"); + queryParam.setPageNo(1); + queryParam.setPageSize(10); + + DataSourceSelector selector = new DataSourceSelector(); + selector.setEnvironment(true); +// selector.setEnvironment(false); + + PageResult result = dataSourceService.queryPage(queryParam, selector); + assertNotNull(result.getData()); + } + + @Test + public void testQueryPageWithPermission() { +// userLoginIdentity(false,3L); + userLoginIdentity(true,9L); + + DataSourcePageQueryParam queryParam = new DataSourcePageQueryParam(); + queryParam.setSearchKey("test"); + queryParam.setKind("PRIVATE"); +// queryParam.setKind("SHARED"); + queryParam.setPageNo(1); + queryParam.setPageSize(10); + queryParam.setOrderByList(new ArrayList()); + + DataSourceSelector selector = new DataSourceSelector(); + selector.setEnvironment(true); + + PageResult result = dataSourceService.queryPageWithPermission(queryParam, selector); + assertNotNull(result.getData()); + + } + + @Test + public void testPreConnect() { + + for (DialectProperties dialectProperties : dialectPropertiesList) { + + DataSourcePreConnectParam param = new DataSourcePreConnectParam(); + param.setType(dialectProperties.getDbType()); + param.setUser(dialectProperties.getUsername()); + param.setUrl(dialectProperties.getUrl()); + param.setPassword(dialectProperties.getPassword()); + param.setPort(String.valueOf(dialectProperties.getPort())); + param.setHost("183.247.151.185"); + param.setSsh(new SSHInfo()); + param.setSsl(new SSLInfo()); + param.setExtendInfo(new ArrayList()); + + ActionResult result = dataSourceService.preConnect(param); + assertNotNull(result); + + Long consoleId= TestUtils.nextLong(); + Long dataSourceId= TestUtils.nextLong(); + TestUtils.buildContext(dialectProperties,dataSourceId,consoleId); + ListResult connect = dataSourceService.connect(dataSourceId); + assertNotNull(connect.getData()); + + dataSourceService.close(dataSourceId); + + } + } + + + /** + * Save the current user identity (administrator or normal user) and user ID to the context and database session for subsequent use. + * + * @param isAdmin + * @param userId + */ + private static void userLoginIdentity(boolean isAdmin, Long userId) { + Context context = Context.builder().loginUser( + LoginUser.builder().admin(isAdmin).id(userId).build() + ).build(); + ContextUtils.setContext(context); + Dbutils.setSession(); + } +} diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DatabaseServiceTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DatabaseServiceTest.java index 04676f380..f619d2098 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DatabaseServiceTest.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DatabaseServiceTest.java @@ -36,7 +36,7 @@ public class DatabaseServiceTest extends TestApplication { @Test public void testQueryAll() { - // MYSQL ORACLE POSTGRESQL + // MYSQL ORACLE POSTGRESQL MONGODB MARIADB for (DialectProperties dialectProperties : dialectPropertiesList) { String dbType = dialectProperties.getDbType(); Long dataSourceId = TestUtils.nextLong(); diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DlTemplateServiceTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DlTemplateServiceTest.java new file mode 100644 index 000000000..dd96ba4cb --- /dev/null +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/core/DlTemplateServiceTest.java @@ -0,0 +1,168 @@ +package ai.chat2db.server.start.test.core; + +import ai.chat2db.server.domain.api.param.DlExecuteParam; +import ai.chat2db.server.domain.api.service.DlTemplateService; +import ai.chat2db.server.domain.repository.Dbutils; +import ai.chat2db.server.start.test.TestApplication; +import ai.chat2db.server.start.test.dialect.DialectProperties; +import ai.chat2db.server.start.test.dialect.TestUtils; +import ai.chat2db.server.tools.base.wrapper.result.DataResult; +import ai.chat2db.server.tools.base.wrapper.result.ListResult; +import ai.chat2db.server.tools.common.model.Context; +import ai.chat2db.server.tools.common.model.LoginUser; +import ai.chat2db.server.tools.common.util.ContextUtils; +import ai.chat2db.spi.model.ExecuteResult; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.sql.Timestamp; +import java.util.Date; +import java.util.List; + + +public class DlTemplateServiceTest extends TestApplication { + + @Autowired + private DlTemplateService dlTemplateService; + + @Autowired + private List dialectPropertiesList; + + // MYSQL: ali_dbhub_test -- test_data + // POSTGRESQL: ali_dbhub_test -- test -- test_data + // ORACLE: TEST_USER -- test_data + @Test + public void testExecute() { + + userLoginIdentity(false, 6L); + + for (DialectProperties dialectProperties : dialectPropertiesList) { + Long dataSourceId = 11L; + Long consoleId = TestUtils.nextLong(); + TestUtils.buildContext(dialectProperties, dataSourceId, consoleId); + + String testData = dialectProperties.getCrateTableSql("test_data006"); + DlExecuteParam dlExecuteParam = new DlExecuteParam(); + dlExecuteParam.setSql(testData); + dlExecuteParam.setConsoleId(consoleId); + dlExecuteParam.setDataSourceId(dataSourceId); + dlExecuteParam.setTableName("test_data006"); + dlExecuteParam.setPageNo(1); + dlExecuteParam.setPageSize(10); + dlExecuteParam.setPageSizeAll(false); + if (dialectProperties.getDbType().equals("POSTGRESQL")) { + dlExecuteParam.setDatabaseName(dialectProperties.getDatabaseName()); + dlExecuteParam.setSchemaName("public"); + } else if (dialectProperties.getDbType().equals("ORACLE")) { + dlExecuteParam.setDatabaseName(""); + dlExecuteParam.setSchemaName("TEST_USER"); + } else if (dialectProperties.getDbType().equals("MYSQL")) { + dlExecuteParam.setDatabaseName(dialectProperties.getDatabaseName()); + dlExecuteParam.setSchemaName(""); + } else { + continue; + } + + + ListResult execute = dlTemplateService.execute(dlExecuteParam); + Assertions.assertTrue(execute.getSuccess(), execute.errorMessage()); + + } + + } + + @Test + public void testExecuteSelectTable() { + + userLoginIdentity(false, 3L); + + for (DialectProperties dialectProperties : dialectPropertiesList) { + Long dataSourceId = 20858L; + Long consoleId = TestUtils.nextLong(); + TestUtils.buildContext(dialectProperties, dataSourceId, consoleId); + + if (dialectProperties.getDbType().equals("MYSQL")) { + DlExecuteParam dlExecuteParam = new DlExecuteParam(); + dlExecuteParam.setConsoleId(consoleId); + dlExecuteParam.setDataSourceId(dataSourceId); + dlExecuteParam.setTableName("test_data004"); + dlExecuteParam.setPageNo(1); + dlExecuteParam.setPageSize(10); + dlExecuteParam.setPageSizeAll(false); + + ListResult execute = dlTemplateService.executeSelectTable(dlExecuteParam); + Assertions.assertTrue(execute.getSuccess(), execute.errorMessage()); + } + + } + } + + @Test + public void testExecuteUpdate() { + + userLoginIdentity(false, 7L); + + for (DialectProperties dialectProperties : dialectPropertiesList) { + Long dataSourceId = TestUtils.nextLong(); + Long consoleId = TestUtils.nextLong(); + TestUtils.buildContext(dialectProperties, dataSourceId, consoleId); + + String testData = dialectProperties.getInsertSql("test_data006", new Timestamp(new Date().getTime()), 1L, "test"); + DlExecuteParam dlExecuteParam = new DlExecuteParam(); + dlExecuteParam.setSql(testData); + dlExecuteParam.setConsoleId(consoleId); + dlExecuteParam.setDataSourceId(dataSourceId); + dlExecuteParam.setTableName("test_data006"); + dlExecuteParam.setPageNo(1); + dlExecuteParam.setPageSize(10); + dlExecuteParam.setPageSizeAll(false); + if (dialectProperties.getDbType().equals("POSTGRESQL")) { + dlExecuteParam.setDatabaseName(dialectProperties.getDatabaseName()); + dlExecuteParam.setSchemaName("public"); + } else if (dialectProperties.getDbType().equals("ORACLE")) { + dlExecuteParam.setDatabaseName(""); + dlExecuteParam.setSchemaName("TEST_USER"); + } else if (dialectProperties.getDbType().equals("MYSQL")) { + dlExecuteParam.setDatabaseName(dialectProperties.getDatabaseName()); + dlExecuteParam.setSchemaName(""); + } else { + continue; + } + + + DataResult result = dlTemplateService.executeUpdate(dlExecuteParam); + Assertions.assertTrue(result.getSuccess(), result.errorMessage()); + + } + } + + @Test + public void testCount() { + + } + + @Test + public void testUpdateSelectResult() { + + } + + @Test + public void testGetOrderBySql() { + + } + + /** + * Save the current user identity (administrator or normal user) and user ID to the context and database session for subsequent use. + * + * @param isAdmin + * @param userId + */ + private static void userLoginIdentity(boolean isAdmin, Long userId) { + Context context = Context.builder().loginUser( + LoginUser.builder().admin(isAdmin).id(userId).build() + ).build(); + ContextUtils.setContext(context); + Dbutils.setSession(); + } +} diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/dialect/OracleDialectProperties.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/dialect/OracleDialectProperties.java index 0eac03a52..58f86e4ef 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/dialect/OracleDialectProperties.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/dialect/OracleDialectProperties.java @@ -16,12 +16,12 @@ public String getDbType() { @Override public String getUrl() { - return "jdbc:oracle:thin:@183.247.151.185:11521:XE"; + return "jdbc:oracle:thin:@192.168.0.120:1521:XE"; } @Override public String getErrorUrl() { - return "jdbc:oracle:thin:@183.247.151.185:11521:XE1"; + return "jdbc:oracle:thin:@192.168.0.120:1521:XE1"; } @Override @@ -41,16 +41,12 @@ public String getDatabaseName() { @Override public String getCrateTableSql(String tableName) { - return "CREATE TABLE `" + tableName + "`\n\t" - + "(\n\t" - + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t" - + " `date` datetime(3) not null COMMENT 'date',\n\t" - + " `number` bigint COMMENT 'long integer',\n\t" - + " `string` VARCHAR(100) default 'DATA' COMMENT 'name',\n\t" - + " index " + tableName + "_idx_date (date desc) comment 'date index',\n\t" - + " unique " + tableName + "_uk_number (number) comment 'unique index',\n\t" - + " index " + tableName + "_idx_number_string (number, date) comment 'Union index'\n\t" - + ") COMMENT ='Test table';"; + return "CREATE TABLE TEST_USER." + tableName + " (\n" + + " id NUMBER PRIMARY KEY,\n" + + " created_date DATE,\n" + + " amount INT,\n" + + " string VARCHAR2(100)\n" + + ");"; } @Override @@ -60,7 +56,7 @@ public String getDropTableSql(String tableName) { @Override public String getInsertSql(String tableName, Date date, Long number, String string) { - return "INSERT INTO `" + tableName + "` (date,number,string) VALUES ('" + DateUtil.format(date, + return "INSERT INTO TEST_USER." + tableName + " (date,number,string) VALUES ('" + DateUtil.format(date, DatePattern.NORM_DATETIME_MS_FORMAT) + "','" + number + "','" + string + "');"; } diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/dialect/PostgresqlDialectProperties.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/dialect/PostgresqlDialectProperties.java index ac81c7cb1..8c7172fc4 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/dialect/PostgresqlDialectProperties.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/dialect/PostgresqlDialectProperties.java @@ -58,17 +58,6 @@ public String getCrateTableSql(String tableName) { + " number int,\n" + " string varchar(100) default 'DATA'\n" + ");\n"; - sql += "comment on table " + tableName + " is 'Test table';\n"; - sql += "comment on column " + tableName + ".id is 'Primary key auto-increment';\n"; - sql += "comment on column " + tableName + ".date is 'date';\n"; - sql += "comment on column " + tableName + ".number is 'long integer';\n"; - sql += "comment on column " + tableName + ".string is 'name';\n"; - sql += "create index " + tableName + "idx_date on " + tableName + " (date desc);"; - sql += "create unique index " + tableName + "_uk_number on " + tableName + " (number);"; - sql += "create index " + tableName + "_idx_number_string on " + tableName + " (number, date);"; - sql += "comment on index " + tableName + "_uk_number is 'date index';"; - sql += "comment on index " + tableName + "_uk_number is 'unique index';"; - sql += "comment on index " + tableName + "_idx_number_string is 'Union index';"; return sql; }