Skip to content

Commit 0604ed8

Browse files
authored
Merge branch 'dev' into timeplus-plugin
2 parents 738f156 + a446482 commit 0604ed8

19 files changed

Lines changed: 1325 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Double click package to install
4040
- modelscope:[Chat2DB-SQL-7B](https://modelscope.cn/models/Chat2DB/Chat2DB-SQL-7B/summary)
4141

4242
### Deploy the InternLM model on Chat2DB
43+
4344
Thanks to [InternLM](https://github.com/InternLM/InternLM) for the strong support for this project. In the custom models of this project, multiple model weights from InternLM can be integrated. For more details, please refer to [chat2db-internlm-deploy](https://github.com/chat2db/chat2db-internlm-deploy)
4445

4546
## Supported databases

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
- modelscope:[Chat2DB-SQL-7B](https://modelscope.cn/models/Chat2DB/Chat2DB-SQL-7B/summary)
7373

7474
### 在Chat2DB上即成InternLM模型
75+
7576
感谢InternLM对本项目的大力支持,在本项目中的自定义模型中,可以集成InternLM的多个模型权重,具体请参考[chat2db-internlm-deploy](https://github.com/chat2db/chat2db-internlm-deploy)
7677

7778
## 支持的数据库

chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/type/PostgreSQLColumnTypeEnum.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum PostgreSQLColumnTypeEnum implements ColumnBuilder {
2323
CIDR("CIDR", false, false, true, false, false, false, true, true, false, false),
2424
CIRCLE("CIRCLE", false, false, true, false, false, false, true, true, false, false),
2525
DATE("DATE", false, false, true, false, false, false, true, true, false, false),
26-
DECIMAL("DECIMAL", true, false, true, false, false, false, true, true, false, false),
26+
DECIMAL("DECIMAL", true, true, true, false, false, false, true, true, false, false),
2727
FLOAT4("FLOAT4", false, false, true, false, false, false, true, true, false, false),
2828
FLOAT8("FLOAT8", false, false, true, false, false, false, true, true, false, false),
2929
INET("INET", false, false, true, false, false, false, true, true, false, false),
@@ -37,7 +37,7 @@ public enum PostgreSQLColumnTypeEnum implements ColumnBuilder {
3737
LSEG("LSEG", false, false, true, false, false, false, true, true, false, false),
3838
MACADDR("MACADDR", false, false, true, false, false, false, true, true, false, false),
3939
MONEY("MONEY", false, false, true, false, false, false, true, true, false, false),
40-
NUMERIC("NUMERIC", true, false, true, false, false, false, true, true, false, false),
40+
NUMERIC("NUMERIC", true, true, true, false, false, false, true, true, false, false),
4141
PATH("PATH", false, false, true, false, false, false, true, true, false, false),
4242
POINT("POINT", false, false, true, false, false, false, true, true, false, false),
4343
POLYGON("POLYGON", false, false, true, false, false, false, true, true, false, false),
Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
package ai.chat2db.server.start.test.core;
22

3+
import ai.chat2db.server.domain.api.model.OperationLog;
4+
import ai.chat2db.server.domain.api.param.operation.OperationLogCreateParam;
5+
import ai.chat2db.server.domain.api.param.operation.OperationLogPageQueryParam;
36
import ai.chat2db.server.domain.api.service.OperationLogService;
7+
import ai.chat2db.server.domain.repository.Dbutils;
48
import ai.chat2db.server.start.test.TestApplication;
9+
import ai.chat2db.server.start.test.dialect.DialectProperties;
10+
import ai.chat2db.server.start.test.dialect.TestUtils;
11+
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
12+
import ai.chat2db.server.tools.base.wrapper.result.PageResult;
13+
import ai.chat2db.server.tools.common.model.Context;
14+
import ai.chat2db.server.tools.common.model.LoginUser;
15+
import ai.chat2db.server.tools.common.util.ContextUtils;
16+
import org.junit.jupiter.api.Assertions;
517
import org.junit.jupiter.api.Test;
618
import org.springframework.beans.factory.annotation.Autowired;
719

20+
import java.util.List;
21+
822
/**
923
* @author Juechen
1024
* @version : OperationLogServiceTest.java
@@ -14,14 +28,67 @@ public class OperationLogServiceTest extends TestApplication {
1428
@Autowired
1529
private OperationLogService operationLogService;
1630

31+
@Autowired
32+
private List<DialectProperties> dialectPropertiesList;
33+
34+
1735
@Test
1836
public void testCreate() {
19-
operationLogService.create(null);
37+
38+
userLoginIdentity(true, 1L);
39+
40+
for (DialectProperties dialectProperties : dialectPropertiesList) {
41+
Long dataSourceId = TestUtils.nextLong();
42+
Long consoleId = TestUtils.nextLong();
43+
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId);
44+
45+
OperationLogCreateParam param = new OperationLogCreateParam();
46+
param.setDataSourceId(dataSourceId);
47+
param.setType(dialectProperties.getDbType());
48+
49+
DataResult<Long> result = operationLogService.create(param);
50+
Assertions.assertTrue(result.success(), result.errorMessage());
51+
}
2052
}
2153

2254
@Test
2355
public void testQueryPage() {
24-
operationLogService.queryPage(null);
56+
userLoginIdentity(false,14L);
57+
58+
for (DialectProperties dialectProperties : dialectPropertiesList) {
59+
Long dataSourceId = TestUtils.nextLong();
60+
Long consoleId = TestUtils.nextLong();
61+
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId);
62+
63+
if (dialectProperties.getDbType().equals("MYSQL")) {
64+
OperationLogPageQueryParam param = new OperationLogPageQueryParam();
65+
param.setDataSourceId(dataSourceId);
66+
param.setSearchKey("test");
67+
param.setUserId(3L);
68+
param.setDatabaseName(dialectProperties.getDatabaseName());
69+
param.setSchemaName("");
70+
param.setPageNo(1);
71+
param.setPageSize(10);
72+
73+
PageResult<OperationLog> queryPage = operationLogService.queryPage(param);
74+
System.out.println(queryPage.getData());
75+
Assertions.assertTrue(queryPage.success(), queryPage.errorMessage());
76+
}
77+
}
78+
}
79+
80+
/**
81+
* Save the current user identity (administrator or normal user) and user ID to the context and database session for subsequent use.
82+
*
83+
* @param isAdmin
84+
* @param userId
85+
*/
86+
private static void userLoginIdentity(boolean isAdmin, Long userId) {
87+
Context context = Context.builder().loginUser(
88+
LoginUser.builder().admin(isAdmin).id(userId).build()
89+
).build();
90+
ContextUtils.setContext(context);
91+
Dbutils.setSession();
2592
}
2693

2794
}
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package ai.chat2db.server.start.test.core;
2+
3+
import ai.chat2db.server.domain.api.model.Operation;
4+
import ai.chat2db.server.domain.api.param.operation.OperationPageQueryParam;
5+
import ai.chat2db.server.domain.api.param.operation.OperationQueryParam;
6+
import ai.chat2db.server.domain.api.param.operation.OperationSavedParam;
7+
import ai.chat2db.server.domain.api.param.operation.OperationUpdateParam;
8+
import ai.chat2db.server.domain.api.service.OperationService;
9+
import ai.chat2db.server.domain.repository.Dbutils;
10+
import ai.chat2db.server.start.test.TestApplication;
11+
import ai.chat2db.server.start.test.dialect.DialectProperties;
12+
import ai.chat2db.server.start.test.dialect.TestUtils;
13+
import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
14+
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
15+
import ai.chat2db.server.tools.base.wrapper.result.PageResult;
16+
import ai.chat2db.server.tools.common.model.Context;
17+
import ai.chat2db.server.tools.common.model.LoginUser;
18+
import ai.chat2db.server.tools.common.util.ContextUtils;
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
23+
import java.util.List;
24+
25+
/**
26+
* @author Juechen
27+
* @version : OperationServiceTest.java
28+
*/
29+
public class OperationServiceTest extends TestApplication {
30+
31+
@Autowired
32+
private OperationService operationService;
33+
34+
@Autowired
35+
private List<DialectProperties> dialectPropertiesList;
36+
37+
38+
@Test
39+
public void testCreateWithPermission() {
40+
41+
userLoginIdentity(true, 7L);
42+
43+
for (DialectProperties dialectProperties : dialectPropertiesList) {
44+
Long dataSourceId = TestUtils.nextLong();
45+
Long consoleId = TestUtils.nextLong();
46+
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId);
47+
48+
OperationSavedParam param = new OperationSavedParam();
49+
param.setDataSourceId(dataSourceId);
50+
param.setType(dialectProperties.getDbType());
51+
// param.setStatus("DRAFT");
52+
param.setStatus("RELEASE");
53+
54+
DataResult<Long> result = operationService.createWithPermission(param);
55+
System.out.println(dialectProperties.getDbType() + "---" + result.getData());
56+
Assertions.assertTrue(result.success(), result.getErrorMessage());
57+
}
58+
}
59+
60+
@Test
61+
public void testUpdateWithPermission() {
62+
63+
userLoginIdentity(true, 3L);
64+
65+
for (DialectProperties dialectProperties : dialectPropertiesList) {
66+
Long dataSourceId = TestUtils.nextLong();
67+
Long consoleId = TestUtils.nextLong();
68+
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId);
69+
70+
OperationUpdateParam param = new OperationUpdateParam();
71+
param.setId(9L);
72+
73+
ActionResult result = operationService.updateWithPermission(param);
74+
Assertions.assertTrue(result.success(), result.getErrorMessage());
75+
}
76+
77+
}
78+
79+
@Test
80+
public void testFind() {
81+
userLoginIdentity(true, 6L);
82+
83+
for (DialectProperties dialectProperties : dialectPropertiesList) {
84+
Long dataSourceId = TestUtils.nextLong();
85+
Long consoleId = TestUtils.nextLong();
86+
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId);
87+
88+
DataResult<Operation> result = operationService.find(18L);
89+
Assertions.assertTrue(result.success(), result.getErrorMessage());
90+
}
91+
}
92+
93+
@Test
94+
public void testQueryExistent() {
95+
userLoginIdentity(false, 7L);
96+
97+
for (DialectProperties dialectProperties : dialectPropertiesList) {
98+
Long dataSourceId = TestUtils.nextLong();
99+
Long consoleId = TestUtils.nextLong();
100+
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId);
101+
102+
OperationQueryParam param = new OperationQueryParam();
103+
param.setId(11L);
104+
105+
DataResult<Operation> result = operationService.queryExistent(10L);
106+
DataResult<Operation> result1 = operationService.queryExistent(param);
107+
Assertions.assertTrue(result.success(), result.getErrorMessage());
108+
Assertions.assertTrue(result1.success(), result1.getErrorMessage());
109+
}
110+
}
111+
112+
@Test
113+
public void testDeleteWithPermission() {
114+
115+
userLoginIdentity(true, 8L);
116+
117+
for (DialectProperties dialectProperties : dialectPropertiesList) {
118+
Long dataSourceId = TestUtils.nextLong();
119+
Long consoleId = TestUtils.nextLong();
120+
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId);
121+
122+
OperationSavedParam param = new OperationSavedParam();
123+
param.setDataSourceId(10L);
124+
param.setType(dialectProperties.getDbType());
125+
// param.setStatus("DRAFT");
126+
param.setStatus("RELEASE");
127+
128+
DataResult<Long> service = operationService.createWithPermission(param);
129+
ActionResult result = operationService.deleteWithPermission(service.getData());
130+
Assertions.assertTrue(result.success(), result.getErrorMessage());
131+
132+
}
133+
}
134+
135+
@Test
136+
public void testQueryPage() {
137+
138+
userLoginIdentity(false, 9L);
139+
140+
for (DialectProperties dialectProperties : dialectPropertiesList) {
141+
Long dataSourceId = TestUtils.nextLong();
142+
Long consoleId = TestUtils.nextLong();
143+
TestUtils.buildContext(dialectProperties, dataSourceId, consoleId);
144+
145+
OperationPageQueryParam param = new OperationPageQueryParam();
146+
param.setStatus("RELEASE");
147+
param.setSearchKey("test");
148+
param.setDataSourceId(dataSourceId);
149+
param.setDatabaseName(dialectProperties.getDatabaseName());
150+
param.setTabOpened("Y");
151+
param.setPageNo(1);
152+
param.setPageSize(10);
153+
param.setOrderByDesc(true);
154+
param.setOrderByCreateDesc(true);
155+
156+
PageResult<Operation> result = operationService.queryPage(param);
157+
Assertions.assertTrue(result.success(), result.getErrorMessage());
158+
159+
}
160+
161+
}
162+
163+
/**
164+
* Save the current user identity (administrator or normal user) and user ID to the context and database session for subsequent use.
165+
*
166+
* @param isAdmin
167+
* @param userId
168+
*/
169+
private static void userLoginIdentity(boolean isAdmin, Long userId) {
170+
Context context = Context.builder().loginUser(
171+
LoginUser.builder().admin(isAdmin).id(userId).build()
172+
).build();
173+
ContextUtils.setContext(context);
174+
Dbutils.setSession();
175+
}
176+
}

0 commit comments

Comments
 (0)