Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Multi-Database Support][postgre] add postgre sql and docs #4782

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Apollo 2.2.0
* [[Multi-Database Support] Optimize column define case sensitivity](https://github.com/apolloconfig/apollo/pull/4776)
* [[Multi-Database Support][pg] Where clause need escape, otherwise will request postgre use lowwer case](https://github.com/apolloconfig/apollo/pull/4780)
* [Misc dependency updates](https://github.com/apolloconfig/apollo/pull/4784)
* [[Multi-Database Support][postgre] add postgre sql and docs](https://github.com/apolloconfig/apollo/pull/4782)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/13?closed=1)
130 changes: 124 additions & 6 deletions docs/zh/deployment/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ SHOW VARIABLES WHERE Variable_name = 'version';
安装包共50M,如果访问github网速不给力的话,可以从百度网盘下载。

1. 从GitHub下载
* checkout或下载[apollo-build-scripts项目](https://github.com/nobodyiam/apollo-build-scripts)
* checkout或下载[apollo-build-scripts项目](https://github.com/apolloconfig/apollo-quick-start)
* **由于Quick Start项目比较大,所以放在了另外的repository,请注意项目地址**
* https://github.com/nobodyiam/apollo-build-scripts
* https://github.com/apolloconfig/apollo-quick-start
2. 从百度网盘下载
* 通过[网盘链接](https://pan.baidu.com/s/1Ieelw6y3adECgktO0ea0Gg)下载,提取码: 9wwe
* 下载到本地后,在本地解压apollo-quick-start.zip
Expand All @@ -73,7 +73,7 @@ Apollo服务端共需要两个数据库:`ApolloPortalDB`和`ApolloConfigDB`,
> 注意:如果你本地已经创建过Apollo数据库,请注意备份数据。我们准备的sql文件会清空Apollo相关的表。

### 2.1.1 创建ApolloPortalDB
通过各种MySQL客户端导入[sql/apolloportaldb.sql](https://github.com/nobodyiam/apollo-build-scripts/blob/master/sql/apolloportaldb.sql)即可。
通过各种MySQL客户端导入[sql/apolloportaldb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloportaldb.sql)即可。

下面以MySQL原生客户端为例:
```sql
Expand All @@ -90,7 +90,7 @@ select `Id`, `AppId`, `Name` from ApolloPortalDB.App;
| 1 | SampleApp | Sample App |

### 2.1.2 创建ApolloConfigDB
通过各种MySQL客户端导入[sql/apolloconfigdb.sql](https://github.com/nobodyiam/apollo-build-scripts/blob/master/sql/apolloconfigdb.sql)即可。
通过各种MySQL客户端导入[sql/apolloconfigdb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloconfigdb.sql)即可。

下面以MySQL原生客户端为例:
```sql
Expand All @@ -106,7 +106,7 @@ select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item;
| 1 | timeout | 100 | sample timeout配置 |

## 2.2 配置数据库连接信息
Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑[demo.sh](https://github.com/nobodyiam/apollo-build-scripts/blob/master/demo.sh),修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。
Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑[demo.sh](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh),修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。

> 注意:填入的用户需要具备对ApolloPortalDB和ApolloConfigDB数据的读写权限。

Expand Down Expand Up @@ -172,7 +172,7 @@ Quick Start只是用来帮助大家快速体验Apollo项目,具体实际使用

> Quick Start集成了[Spring Security简单认证](zh/development/portal-how-to-implement-user-login-function#实现方式一:使用apollo提供的spring-security简单认证),更多信息可以参考[Portal 实现用户登录功能](zh/development/portal-how-to-implement-user-login-function)

<img src="https://github.com/nobodyiam/apollo-build-scripts/raw/master/images/apollo-login.png" alt="登录" width="640px">
<img src="https://github.com/apolloconfig/apollo-quick-start/raw/master/images/apollo-login.png" alt="登录" width="640px">

2. 输入用户名apollo,密码admin后登录

Expand Down Expand Up @@ -248,3 +248,121 @@ Apollo Config Demo. Please input key to get the value. Input quit to exit.
app.id=你的appId
```
运行`./demo.sh client`启动Demo客户端即可。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the default database for quick start?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nobodyiam I think it will be mysql, since we haven't finish h2 feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mysql is the default, then section 5.2 is not necessary?

# 五、使用其它数据库

## 5.1 PostgresSQL

### 5.1.1 初始化ApolloPortalDB和ApolloConfigDB数据库。

方式一: 通过各种pg客户端导入sql/postgre/apollo_init_user.sql即可。

方式二: 下面以postgresql原生客户端为例:

```\i /your_local_path/sql/postgre/apollo_init_user.sql```

### 5.1.2 初始化ApolloPortalDB数据库表

方式一: 通过各种pg客户端导入sql/postgre/apolloportaldb.sql即可。

方式二: 下面以postresql原生客户端为例

```\i /your_local_path/sql/postgre/apolloportaldb.sql```

导入成功后,可以通过执行以下sql语句来验证:

```\c ApolloPortalDB```

```select "Id", "AppId", "Name" from apolloportal."App";```


| Id | AppId | Name |
|----|-----------|------------|

### 5.1.3 初始化ApolloConfigDB数据库表

方式一: 通过各种pg客户端导入sql/postgre/apolloconfigdb.sql即可。

方式二: 下面以postresql原生客户端为例

```\i /your_local_path/sql/postgre/apolloconfigdb.sql```

导入成功后,可以通过执行以下sql语句来验证:

```\c ApolloConfigDB```

```select "Id", "Key", "Cluster" from apolloconfig."ServerConfig";```


| Id | Key | Cluster |
|----|-----------|------------|

### 5.1.4 配置数据库连接信息

Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑[demo.sh](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh),修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。

```
# database platform
spring_profiles_group_github=postgre

# apollo portal db info
apollo_portal_db_url="jdbc:postgresql://localhost:5432/ApolloPortalDB?currentSchema=apolloportal&characterEncoding=utf8"
apollo_portal_db_username=用户名
apollo_portal_db_password=密码(如果没有密码,留空即可)

#apollo config db info
apollo_config_db_url="jdbc:postgresql://localhost:5432/ApolloConfigDB?currentSchema=apolloconfig&characterEncoding=utf8"
apollo_config_db_username=用户名
apollo_config_db_password=密码(如果没有密码,留空即可)

```

## 5.2 MySQL

### 5.2.1 初始化ApolloPortalDB数据库及表结构。

方式一: 通过各种MySQL客户端导入sql/apolloportaldb.sql即可。

方式二: 下面以MySQL原生客户端为例:

```source /your_local_path/sql/apolloportaldb.sql```

导入成功后,可以通过执行以下sql语句来验证:

```select `Id`, `AppId`, `Name` from ApolloPortalDB.App;```


| Id | AppId | Name |
|----|-----------|------------|
| 1 | SampleApp | Sample App |

#### 5.2.2 初始化ApolloConfigDB数据库及表结构

方式一: 通过各种MySQL客户端导入sql/apolloconfigdb.sql即可。

方式二: 下面以MySQL原生客户端为例:

```source /your_local_path/sql/apolloconfigdb.sql```

导入成功后,可以通过执行以下sql语句来验证:

```select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item;```

| NamespaceId | Key | Value | Comment |
|-------------|---------|-------|--------------------|
| 1 | timeout | 100 | sample timeout配置 |

#### 5.2.3 配置数据库连接信息

Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑[demo.sh](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh),修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。
```
#apollo config db info
apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_config_db_username=用户名
apollo_config_db_password=密码(如果没有密码,留空即可)

# apollo portal db info
apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_portal_db_username=用户名
apollo_portal_db_password=密码(如果没有密码,留空即可)
```
49 changes: 49 additions & 0 deletions scripts/sql/postgre/apollo_init_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--
-- Copyright 2023 Apollo Authors
--
-- 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.
--
/* # CREATE apolloconfigdb; */
/* # ------------------------------------------------------------ */

CREATE DATABASE "ApolloConfigDB";

\c "ApolloConfigDB"

CREATE SCHEMA apolloconfig;

GRANT ALL PRIVILEGES ON DATABASE "ApolloConfigDB" to postgres;

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA apolloconfig to postgres;

GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA apolloconfig to postgres;

GRANT ALL PRIVILEGES ON SCHEMA apolloconfig TO postgres;


/* # CREATE apolloconfigdb; */
/* # ------------------------------------------------------------ */

CREATE DATABASE "ApolloPortalDB";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Postgres is very different from MySQL, which would make future contributions harder.
I'm thinking how about we abstract a storage layer this time and move the Postgres support to a new git repository, e.g. apollo-storage-extensions? The apollo-storage-extensions repository would target a specific version of apollo and doesn't have to be updated every time a feature is added. It would instead be updated by some Postgres user from time to time when they think is necessary.

cc @apolloconfig/committers what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I humbly suggest that we create a separate folder for now, as we are not entirely clear on which boundaries should be placed between multiple databases in the main code and extensions. My recommendation is that we start by placing PostgreSQL and other databases in a separate folder. Once we have successfully achieved compatibility with one or two databases, we can then begin to separate the repository.
cc @apolloconfig/committers


\c "ApolloPortalDB"

CREATE SCHEMA apolloportal;

GRANT ALL PRIVILEGES ON DATABASE "ApolloPortalDB" to postgres;

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA apolloportal to postgres;

GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA apolloportal to postgres;

GRANT ALL PRIVILEGES ON SCHEMA apolloportal TO postgres;
Loading