Skip to content

Commit

Permalink
PullRequest: 504 feat/dev-4.3.2-pg
Browse files Browse the repository at this point in the history
Merge branch 'feat/dev-4.3.2-pg of [email protected]:oceanbase/oceanbase-developer-center.git into dev-4.3.2

https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/504


Signed-off-by: 晓康 <[email protected]>


* feat: support pg
* feat: POSTGRE_SQL -> POSTGRESQL
* feat: pg datasource need database name
* feat: data clear supports oracle db
  • Loading branch information
yezaoshu committed Aug 16, 2024
1 parent 194516b commit 3c76f02
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 1 deletion.
1 change: 1 addition & 0 deletions .secignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
http://www.apache.org*
https://dev.mysql.com*
https://open.feishu.cn*
https://jdbc.postgresql.org*

--------------------------------------------------------
# Should use GLOB wildcard to config and analysis the ignored folder
Expand Down
13 changes: 13 additions & 0 deletions src/common/datasource/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ import obMySQL from './oceanbase/obmysql';
import oracle from './oracle';
import MySQL from './mysql';
import Doris from './doris';
import PG from './pg';
import { ReactComponent as OBSvg } from '@/svgr/source_ob.svg';
import { ReactComponent as DBOBSvg } from '@/svgr/database_oceanbase.svg';
import { ReactComponent as MySQLSvg } from '@/svgr/mysql.svg';
import { ReactComponent as DBMySQLSvg } from '@/svgr/database_mysql.svg';
import { ReactComponent as DorisSvg } from '@/svgr/doris.svg';
import { ReactComponent as PGSvg } from '@/svgr/pg.svg';
import { ReactComponent as DBDorisSvg } from '@/svgr/database_doris.svg';
import { ReactComponent as OracleSvg } from '@/svgr/oracle.svg';
import { ReactComponent as DBOracleSvg } from '@/svgr/database_oracle.svg';
import { ReactComponent as DBPGSvg } from '@/svgr/database_pg.svg';

const _types: Map<
IDataSourceType,
Expand Down Expand Up @@ -78,6 +81,15 @@ const _styles = {
component: DBOracleSvg,
},
},
[IDataSourceType.PG]: {
icon: {
component: PGSvg,
color: '#000000',
},
dbIcon: {
component: DBPGSvg,
},
},
};

const connectType2Ds: Map<ConnectType, IDataSourceType> = new Map();
Expand Down Expand Up @@ -121,6 +133,7 @@ register(IDataSourceType.OceanBase, obMySQL);
register(IDataSourceType.MySQL, MySQL);
register(IDataSourceType.Doris, Doris);
register(IDataSourceType.Oracle, oracle);
register(IDataSourceType.PG, PG);

function getAllConnectTypes(ds?: IDataSourceType): ConnectType[] {
if (!ds) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/datasource/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface IDataSourceModeConfig {
priority?: number;
connection: {
address: {
items: ('ip' | 'port' | 'cluster' | 'tenant' | 'sid')[];
items: ('ip' | 'port' | 'cluster' | 'tenant' | 'sid' | 'databaseName')[];
};
account: boolean;
role?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/common/datasource/oracle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const items: Record<ConnectType.ORACLE, IDataSourceModeConfig> = {
TaskType.EXPORT_RESULT_SET,
TaskType.SQL_PLAN,
TaskType.ASYNC,
TaskType.DATA_DELETE,
TaskType.DATA_ARCHIVE,
],
obclient: false,
Expand Down
97 changes: 97 additions & 0 deletions src/common/datasource/pg/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2023 OceanBase
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ConnectType, TaskType } from '@/d.ts';
import { IDataSourceModeConfig } from '../interface';
import MySQLColumnExtra from '../oceanbase/MySQLColumnExtra';
import { haveOCP } from '@/util/env';

const tableConfig = {
enableTableCharsetsAndCollations: true,
enableConstraintOnUpdate: true,
ColumnExtraComponent: MySQLColumnExtra,
paritionNameCaseSensitivity: true,
enableIndexesFullTextType: true,
enableAutoIncrement: true,
type2ColumnType: {
id: 'int',
name: 'varchar',
date: 'datetime',
time: 'timestamp',
},
};

const functionConfig: IDataSourceModeConfig['schema']['func'] = {
params: ['paramName', 'dataType', 'dataLength'],
defaultValue: {
dataLength: 45,
},
dataNature: true,
sqlSecurity: true,
deterministic: true,
};

const procedureConfig: IDataSourceModeConfig['schema']['proc'] = {
params: ['paramName', 'paramMode', 'dataType', 'dataLength'],
defaultValue: {
dataLength: 45,
},
dataNature: true,
sqlSecurity: true,
deterministic: true,
};

const items: Record<ConnectType.PG, IDataSourceModeConfig> = {
[ConnectType.PG]: {
connection: {
address: {
items: ['ip', 'port', 'databaseName'],
},
account: true,
sys: false,
ssl: false,
jdbcDoc: 'https://jdbc.postgresql.org/documentation/use/',
},
features: {
task: [TaskType.DATA_ARCHIVE, TaskType.DATA_DELETE],
obclient: false,
recycleBin: false,
sessionManage: false,
sqlExplain: false,
export: {
fileLimit: false,
snapshot: false,
},
},
schema: {
table: tableConfig,
func: functionConfig,
proc: procedureConfig,
innerSchema: ['postgres'],
},
sql: {
language: 'mysql',
escapeChar: '"',
caseSensitivity: true,
},
},
};

if (haveOCP()) {
delete items[ConnectType.PG];
}

export default items;
1 change: 1 addition & 0 deletions src/common/network/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function generateConnectionParams(formData: Partial<IConnectionFormData>, isHide
jdbcUrlParameters: formData.jdbcUrlParameters || {},
temp: isHiden,
sessionInitScript: formData.sessionInitScript,
databaseName: formData?.databaseName,
};
const config = getDataSourceModeConfig(formData.type)?.connection;
config?.address?.items?.forEach((item) => {
Expand Down
1 change: 1 addition & 0 deletions src/constant/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const ConnectTypeText = {
[ConnectType.MYSQL]: 'MySQL',
[ConnectType.DORIS]: 'Doris',
[ConnectType.ORACLE]: 'Oracle',
[ConnectType.PG]: 'PostgreSQL',
};

export const DragInsertTypeText = {
Expand Down
1 change: 1 addition & 0 deletions src/d.ts/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export enum IDataSourceType {
MySQL = 'mysql',
Doris = 'doris',
Oracle = 'oracle',
PG = 'postgresql',
}
4 changes: 4 additions & 0 deletions src/d.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ export enum AuditEventDialectType {
ORACLE = 'ORACLE',
MYSQL = 'MYSQL',
DORIS = 'DORIS',
PG = 'POSTGRESQL',
UNKNOWN = 'UNKNOWN',
}

Expand Down Expand Up @@ -732,6 +733,7 @@ export type ISQLScript = IScriptMeta;
export enum ConnectionMode {
MYSQL = 'MYSQL',
DORIS = 'DORIS',
PG = 'POSTGRESQL',
ORACLE = 'ORACLE',
OB_MYSQL = 'OB_MYSQL',
OB_ORACLE = 'OB_ORACLE',
Expand Down Expand Up @@ -822,6 +824,7 @@ export interface IConnection {
serviceName?: string;
userRole?: string;
readonly projectName?: string;
databaseName?: string;
}

export interface IConnectionLabel {
Expand Down Expand Up @@ -3285,6 +3288,7 @@ export enum ConnectType {
ODP_SHARDING_OB_MYSQL = 'ODP_SHARDING_OB_MYSQL',
MYSQL = 'MYSQL',
DORIS = 'DORIS',
PG = 'POSTGRESQL',
ORACLE = 'ORACLE',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ const AddressItems: React.FC<IProps> = function (props) {
</Col>
);
}
case 'databaseName': {
return (
<Col span={24}>
<Form.Item
required
label={`数据库名称`}
rules={[{ required: true, message: '请输入数据库名称' }]}
style={{ width: '100%', marginLeft: -1 }}
name="databaseName"
>
<Input style={{ width: '100%' }} />
</Form.Item>
</Col>
);
}
default: {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default forwardRef<IFormRef, IProps>(function DatasourceForm(
'sid',
'serviceName',
'userRole',
'databaseName',
]);
} catch (e) {}
if (!values) {
Expand Down
23 changes: 23 additions & 0 deletions src/page/Datasource/Datasource/NewDatasourceDrawer/NewButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const NewDatasourceButton: React.FC<{
const mysqlConnectTypes = getAllConnectTypes(IDataSourceType.MySQL);
const dorisConnectTypes = getAllConnectTypes(IDataSourceType.Doris);
const oracleConnectTypes = getAllConnectTypes(IDataSourceType.Oracle);
const pgConnectTypes = getAllConnectTypes(IDataSourceType.PG);

const batchImportRef = useRef<{
closeModal: () => void;
Expand Down Expand Up @@ -164,6 +165,28 @@ const NewDatasourceButton: React.FC<{
}),
);
}
if (pgConnectTypes?.length) {
results.push({
type: 'divider',
});
results = results.concat(
pgConnectTypes.map((item) => {
return {
label: ConnectTypeText[item],
key: item,
icon: (
<Icon
component={getDataSourceStyleByConnectType(item)?.icon?.component}
style={{
color: getDataSourceStyleByConnectType(item)?.icon?.color,
fontSize: '16px',
}}
/>
),
};
}),
);
}
if (!haveOCP()) {
results.push({
type: 'divider',
Expand Down
7 changes: 7 additions & 0 deletions src/page/Datasource/Info/NewDataBaseButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ export default function NewDataBaseButton({
});
return;
}
case ConnectionMode.PG: {
form.setFieldsValue({
collationName: 'C',
charsetName: 'UTF8',
});
return;
}
}
}, [mode, open]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const mysqlObjectType = [
DbObjectType.procedure,
];

const pgObjectType = [
DbObjectType.table,
DbObjectType.column,
DbObjectType.function,
DbObjectType.view,
DbObjectType.trigger,
];

const oracleObjectType = [
DbObjectType.database,
DbObjectType.table,
Expand All @@ -42,6 +50,7 @@ export const objectTypeConfig = {
[ConnectType.OB_MYSQL]: mysqlObjectType,
[ConnectType.MYSQL]: mysqlObjectType,
[ConnectType.DORIS]: mysqlObjectType,
[ConnectType.PG]: pgObjectType,
[ConnectType.OB_ORACLE]: oracleObjectType,
[ConnectType.ORACLE]: oracleObjectType,
SEARCH_OBJECT_FROM_ALL_DATABASE: oracleObjectType,
Expand Down
1 change: 1 addition & 0 deletions src/svgr/database_pg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3c76f02

Please sign in to comment.