Skip to content

Commit

Permalink
[migrate] replace PostgreSQL with MySQL/MariaDB
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Nov 26, 2023
1 parent 41aedbf commit 71a2e14
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 156 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
README.md
*.example
node_modules/
.data/
.editorconfig
.eslintrc.json
Dockerfile
Expand Down
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ TRANSFER_TOKEN_SALT = tobemodified
JWT_SECRET = tobemodified
ADMIN_JWT_SECRET = tobemodified

DATABASE_URL = postgres://user:password@host:port/database
DATABASE_CLIENT = mysql2
DATABASE_HOST = mysql-server
DATABASE_USERNAME = root
DATABASE_PASSWORD = your-secret

AZURE_BLOB_BASE_URL = https://your-account.core.chinacloudapi.cn
AZURE_BLOB_CONNECTION = "DefaultEndpointsProtocol=https;AccountName=your-account;AccountKey=your-account-key;EndpointSuffix=core.chinacloudapi.cn"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ $RECYCLE.BIN/
*.sql
*.sqlite
*.sqlite3
.data/


############################
Expand Down
17 changes: 10 additions & 7 deletions config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ export default ({ env }) => {

const connections = {
mysql: {
connection: { ...connection, port: port || 3306, connectionString },
connection: connectionString
? { connectionString }
: { ...connection, port: port || 3306 },
pool,
},
mysql2: {
connection: { ...connection, port: port || 3306 },
pool,
},
postgres: {
connection: {
...connection,
port: port || 5432,
connectionString,
schema: env('DATABASE_SCHEMA', 'public'),
},
connection: connectionString
? { connectionString, schema: env('DATABASE_SCHEMA', 'public') }
: {
...connection,
port: port || 5432,
schema: env('DATABASE_SCHEMA', 'public'),
},
pool,
},
sqlite: {
Expand Down
24 changes: 12 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
version: '3'

services:
postgres-server:
image: postgres
mysql-server:
image: mysql
command: --default-authentication-plugin=mysql_native_password
environment:
- POSTGRES_PASSWORD=${ADMIN_JWT_SECRET}
- MYSQL_ROOT_PASSWORD=${ADMIN_JWT_SECRET}
- MYSQL_DATABASE=strapi
volumes:
- ./data:/var/lib/postgresql/data/
- ./.data:/var/lib/mysql
ports:
- 5433:5432
- 3306:3306
restart: always

strapi-server:
depends_on:
- postgres-server
- mysql-server
image: ohp/strapi-server
environment:
- DATABASE_CLIENT=postgres
- DATABASE_URL=postgres://postgres:${ADMIN_JWT_SECRET}@postgres-server:5433/postgres
- DATABASE_CLIENT=mysql2
- DATABASE_HOST=mysql-server
- DATABASE_USERNAME=root
- DATABASE_PASSWORD=${ADMIN_JWT_SECRET}
- NODE_ENV=production
- PORT=1337
ports:
Expand All @@ -30,10 +34,6 @@ services:
labels:
- autoheal=true
restart: always
logging:
driver: json-file
options:
max-size: 10m

autoheal:
image: willfarrell/autoheal:1.2.0
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@strapi/plugin-users-permissions": "4.15.4",
"@strapi/strapi": "4.15.4",
"better-sqlite3": "9.1.1",
"pg": "^8.11.3",
"mysql2": "^3.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^5.3.4",
Expand Down Expand Up @@ -51,7 +51,7 @@
"develop": "npm run clean && strapi build && strapi develop",
"build": "npm run clean && cross-env NODE_ENV=production strapi build",
"start": "cross-env NODE_ENV=production strapi start",
"pack-image": "docker build -t strapi-server:latest .",
"container": "(docker rm -f strapi-server || true) && docker run --name strapi-server -p 1337:1337 -d strapi-server:latest"
"pack-image": "docker build -t ohp/strapi-server:latest .",
"container": "docker rm -f strapi-server && docker run --name strapi-server -p 1337:1337 -d ohp/strapi-server:latest"
}
}
Loading

0 comments on commit 71a2e14

Please sign in to comment.