mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-22 09:13:37 +01:00
Database build script.
This commit is contained in:
parent
b905824d50
commit
c3da37c0b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,6 +11,7 @@
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
/prisma/schema.prisma
|
||||
|
||||
# production
|
||||
/build
|
||||
|
24
README.md
24
README.md
@ -13,21 +13,11 @@ A detailed getting started guide can be found at [https://umami.is/docs/](https:
|
||||
- A server with Node.js 10.13 or newer
|
||||
- A database (MySQL or Postgresql)
|
||||
|
||||
### Get the source code
|
||||
### Get the source code and install packages
|
||||
|
||||
```
|
||||
git clone https://github.com/mikecao/umami.git
|
||||
```
|
||||
|
||||
### Go into the repo folder
|
||||
|
||||
```
|
||||
cd umami
|
||||
```
|
||||
|
||||
### Install packages
|
||||
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
@ -70,18 +60,8 @@ The `HASH_SALT` is used to generate unique values for your installation.
|
||||
|
||||
### Generate database client
|
||||
|
||||
Depending on your database type, run the appropriate script.
|
||||
|
||||
For MySQL:
|
||||
|
||||
```
|
||||
npm run build-mysql-client
|
||||
```
|
||||
|
||||
For Postgresql:
|
||||
|
||||
```
|
||||
npm run build-postgresql-client
|
||||
npm run build-db-client
|
||||
```
|
||||
|
||||
### Create a production build
|
||||
|
@ -14,10 +14,9 @@
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"build-tracker": "rollup -c rollup.tracker.config.js",
|
||||
"build-mysql-schema": "dotenv prisma introspect -- --schema=./prisma/schema.mysql.prisma",
|
||||
"build-mysql-client": "dotenv prisma generate -- --schema=./prisma/schema.mysql.prisma",
|
||||
"build-postgresql-schema": "dotenv prisma introspect -- --schema=./prisma/schema.postgresql.prisma",
|
||||
"build-postgresql-client": "dotenv prisma generate -- --schema=./prisma/schema.postgresql.prisma"
|
||||
"build-db-client": "node ./scripts/build-db-client.js",
|
||||
"prisma-introspect": "dotenv prisma introspect",
|
||||
"prisma-generate": "dotenv prisma generate"
|
||||
},
|
||||
"lint-staged": {
|
||||
"**/*.js": [
|
||||
|
22
scripts/build-db-client.js
Normal file
22
scripts/build-db-client.js
Normal file
@ -0,0 +1,22 @@
|
||||
require('dotenv').config();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { getDatabase, getNpmCommand, runCommand } = require('./common');
|
||||
|
||||
(async () => {
|
||||
const db = getDatabase();
|
||||
|
||||
if (!db) {
|
||||
throw new Error('Database not specified');
|
||||
}
|
||||
|
||||
const src = path.resolve(__dirname, `../prisma/schema.${db}.prisma`);
|
||||
const dest = path.resolve(__dirname, '../prisma/schema.prisma');
|
||||
|
||||
fs.copyFileSync(src, dest);
|
||||
|
||||
await runCommand(getNpmCommand(), ['run', 'prisma-generate']).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
})();
|
29
scripts/common.js
Normal file
29
scripts/common.js
Normal file
@ -0,0 +1,29 @@
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
function getDatabase() {
|
||||
return process.env.DATABASE_URL.split(':')[0];
|
||||
}
|
||||
|
||||
function runCommand(cmd, args = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(cmd, args);
|
||||
|
||||
child.stdout.on('data', data => process.stdout.write(data));
|
||||
|
||||
child.stderr.on('data', data => process.stdout.write(data));
|
||||
|
||||
child.on('error', err => reject(err));
|
||||
|
||||
child.on('exit', (code, signal) => resolve({ code, signal }));
|
||||
});
|
||||
}
|
||||
|
||||
function getNpmCommand() {
|
||||
return /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDatabase,
|
||||
runCommand,
|
||||
getNpmCommand,
|
||||
};
|
Loading…
Reference in New Issue
Block a user