Moved cli to separate project. Separate database schemas.

This commit is contained in:
Mike Cao 2020-08-13 01:41:11 -07:00
parent 585706cc16
commit 48a524e09c
9 changed files with 248 additions and 788 deletions

View File

@ -1 +1,60 @@
umami - deliciously simple web stats # umami
## Getting started
### Install umami
```
git clone https://github.com/mikecao/umami.git
```
### Go into your repo folder
```
cd umami
```
### Create database tables
Umami supports MySQL and Postgresql. Create a database for your Umami
installation and install the tables with the included scripts.
For MySQL:
```
mysql -u username -p databasename < sql/schema.mysql.sql
```
For Postgresql:
```
psql -h hostname -U username -d databasename -f sql/schema.postgresql.sql
```
### Configure umami
Create an `.env` file with the following
```
DATABASE_URL=(connection url)
HASH_SALT=(any random string)
```
The connection url is in the following format:
```
postgresql://username:mypassword@localhost:5432/mydb
mysql://username:mypassword@localhost:3306/mydb
```
### Start the development server
```
npm run develop
```
### Create a production build
```
npm run build
```

View File

@ -1,27 +0,0 @@
#!/usr/bin/env node
import 'dotenv/config';
import yargs from 'yargs';
import chalk from 'chalk';
import createAccount from './create-account';
const cmd = yargs.usage('Usage: umami <command> [arguments]').help('h').alias('h', 'help');
const { argv } = cmd;
const {
_: [action, ...params],
} = argv;
const exec = async () => {
if (action === 'create') {
await createAccount();
} else {
cmd.showHelp();
}
console.log(chalk.green('Finished.'));
};
exec().then(() => {
process.exit(0);
});

View File

@ -1,7 +0,0 @@
import term from 'terminal-kit';
const { terminal } = term;
export default function init() {
terminal('hello!');
}

View File

@ -20,11 +20,11 @@ let prisma;
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient(options); prisma = new PrismaClient(options);
prisma.on('query', logQuery); prisma.$on('query', logQuery);
} else { } else {
if (!global.prisma) { if (!global.prisma) {
global.prisma = new PrismaClient(options); global.prisma = new PrismaClient(options);
global.prisma.on('query', logQuery); global.prisma.$on('query', logQuery);
} }
prisma = global.prisma; prisma = global.prisma;

View File

@ -1,7 +1,7 @@
{ {
"name": "umami", "name": "umami",
"version": "0.2.0", "version": "0.2.0",
"description": "Deliciously simple website stats", "description": "Delicious web stats",
"author": "Mike Cao <mike@mikecao.com>", "author": "Mike Cao <mike@mikecao.com>",
"license": "MIT", "license": "MIT",
"homepage": "https://github.com/mikecao/umami", "homepage": "https://github.com/mikecao/umami",
@ -9,19 +9,16 @@
"type": "git", "type": "git",
"url": "https://github.com/mikecao/umami.git" "url": "https://github.com/mikecao/umami.git"
}, },
"main": "index.js",
"bin": {
"umami": "cli.js"
},
"scripts": { "scripts": {
"dev": "cross-env LOG_QUERY=1 next dev -p 8000", "dev": "next dev -p 8000",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"build-cli": "rollup -c rollup.cli.config.js", "build-cli": "rollup -c rollup.cli.config.js",
"build-tracker": "rollup -c rollup.tracker.config.js", "build-tracker": "rollup -c rollup.tracker.config.js",
"build-db-schema": "dotenv prisma introspect", "build-mysql-schema": "dotenv prisma introspect -- --schema=./prisma/schema.mysql.prisma",
"build-db-client": "dotenv prisma generate", "build-mysql-client": "dotenv prisma generate -- --schema=./prisma/schema.mysql.prisma",
"create-account": "node cli/create-account.js" "build-postgresql-schema": "dotenv prisma introspect -- --schema=./prisma/schema.postgresql.prisma",
"build-postgresql-client": "dotenv prisma generate -- --schema=./prisma/schema.postgresql.prisma"
}, },
"lint-staged": { "lint-staged": {
"**/*.js": [ "**/*.js": [
@ -41,7 +38,6 @@
"@prisma/client": "2.4.1", "@prisma/client": "2.4.1",
"@reduxjs/toolkit": "^1.4.0", "@reduxjs/toolkit": "^1.4.0",
"bcrypt": "^5.0.0", "bcrypt": "^5.0.0",
"chalk": "^4.1.0",
"chart.js": "^2.9.3", "chart.js": "^2.9.3",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"cookie": "^0.4.1", "cookie": "^0.4.1",
@ -54,11 +50,10 @@
"formik": "^2.1.5", "formik": "^2.1.5",
"geolite2-redist": "^1.0.7", "geolite2-redist": "^1.0.7",
"is-localhost-ip": "^1.4.0", "is-localhost-ip": "^1.4.0",
"jose": "^1.27.3", "jose": "^1.28.0",
"maxmind": "^4.1.4", "maxmind": "^4.1.4",
"moment-timezone": "^0.5.31", "moment-timezone": "^0.5.31",
"next": "9.5.1", "next": "9.5.2",
"node-fetch": "^2.6.0",
"promise-polyfill": "^8.1.3", "promise-polyfill": "^8.1.3",
"react": "16.13.1", "react": "16.13.1",
"react-dom": "16.13.1", "react-dom": "16.13.1",
@ -72,13 +67,11 @@
"request-ip": "^2.1.3", "request-ip": "^2.1.3",
"tinycolor2": "^1.4.1", "tinycolor2": "^1.4.1",
"unfetch": "^4.1.0", "unfetch": "^4.1.0",
"uuid": "^8.3.0", "uuid": "^8.3.0"
"yargs": "^15.4.1"
}, },
"devDependencies": { "devDependencies": {
"@prisma/cli": "2.4.1", "@prisma/cli": "2.4.1",
"@rollup/plugin-buble": "^0.21.3", "@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.4.0", "@rollup/plugin-node-resolve": "^8.4.0",
"@rollup/plugin-replace": "^2.3.3", "@rollup/plugin-replace": "^2.3.3",
"@svgr/webpack": "^5.4.0", "@svgr/webpack": "^5.4.0",
@ -90,7 +83,6 @@
"eslint-plugin-react": "^7.20.5", "eslint-plugin-react": "^7.20.5",
"eslint-plugin-react-hooks": "^4.0.4", "eslint-plugin-react-hooks": "^4.0.4",
"husky": "^4.2.5", "husky": "^4.2.5",
"less": "^3.12.2",
"lint-staged": "^10.2.9", "lint-staged": "^10.2.9",
"postcss-flexbugs-fixes": "^4.2.1", "postcss-flexbugs-fixes": "^4.2.1",
"postcss-import": "^12.0.1", "postcss-import": "^12.0.1",
@ -99,7 +91,7 @@
"prettier-eslint": "^11.0.0", "prettier-eslint": "^11.0.0",
"rollup": "^2.23.1", "rollup": "^2.23.1",
"rollup-plugin-hashbang": "^2.2.2", "rollup-plugin-hashbang": "^2.2.2",
"rollup-plugin-terser": "^6.1.0", "rollup-plugin-terser": "^7.0.0",
"stylelint": "^13.6.0", "stylelint": "^13.6.0",
"stylelint-config-css-modules": "^2.2.0", "stylelint-config-css-modules": "^2.2.0",
"stylelint-config-prettier": "^8.0.1", "stylelint-config-prettier": "^8.0.1",

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,9 @@
drop table if exists event;
drop table if exists pageview;
drop table if exists session;
drop table if exists website;
drop table if exists account;
create table account ( create table account (
user_id int unsigned not null auto_increment primary key, user_id int unsigned not null auto_increment primary key,
username varchar(255) unique not null, username varchar(255) unique not null,
@ -55,6 +61,8 @@ create table event (
foreign key (session_id) references session(session_id) on delete cascade foreign key (session_id) references session(session_id) on delete cascade
) ENGINE=InnoDB; ) ENGINE=InnoDB;
create index website_user_id_idx on website(user_id);
create index session_created_at_idx on session(created_at); create index session_created_at_idx on session(created_at);
create index session_website_id_idx on session(website_id); create index session_website_id_idx on session(website_id);

View File

@ -1,3 +1,9 @@
drop table if exists event;
drop table if exists pageview;
drop table if exists session;
drop table if exists website;
drop table if exists account;
create table account ( create table account (
user_id serial primary key, user_id serial primary key,
username varchar(255) unique not null, username varchar(255) unique not null,
@ -49,6 +55,8 @@ create table event (
event_value varchar(50) not null event_value varchar(50) not null
); );
create index website_user_id_idx on website(user_id);
create index session_created_at_idx on session(created_at); create index session_created_at_idx on session(created_at);
create index session_website_id_idx on session(website_id); create index session_website_id_idx on session(website_id);

891
yarn.lock

File diff suppressed because it is too large Load Diff