Moved cli to separate project. Separate database schemas.
This commit is contained in:
1 parent
585706cc16
commit
48a524e09c
9 files changed
+248
-788
No files matched your search
@@ -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
|
||||
```
|
||||
@@ -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);
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
import term from 'terminal-kit';
|
||||
|
||||
const { terminal } = term;
|
||||
|
||||
export default function init() {
|
||||
terminal('hello!');
|
||||
}
|
||||
@@ -20,11 +20,11 @@ let prisma;
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = new PrismaClient(options);
|
||||
prisma.on('query', logQuery);
|
||||
prisma.$on('query', logQuery);
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient(options);
|
||||
global.prisma.on('query', logQuery);
|
||||
global.prisma.$on('query', logQuery);
|
||||
}
|
||||
|
||||
prisma = global.prisma;
|
||||
|
||||
+10
-18
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "umami",
|
||||
"version": "0.2.0",
|
||||
"description": "Deliciously simple website stats",
|
||||
"description": "Delicious web stats",
|
||||
"author": "Mike Cao <mike@mikecao.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/mikecao/umami",
|
||||
@@ -9,19 +9,16 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/mikecao/umami.git"
|
||||
},
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"umami": "cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "cross-env LOG_QUERY=1 next dev -p 8000",
|
||||
"dev": "next dev -p 8000",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"build-cli": "rollup -c rollup.cli.config.js",
|
||||
"build-tracker": "rollup -c rollup.tracker.config.js",
|
||||
"build-db-schema": "dotenv prisma introspect",
|
||||
"build-db-client": "dotenv prisma generate",
|
||||
"create-account": "node cli/create-account.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"
|
||||
},
|
||||
"lint-staged": {
|
||||
"**/*.js": [
|
||||
@@ -41,7 +38,6 @@
|
||||
"@prisma/client": "2.4.1",
|
||||
"@reduxjs/toolkit": "^1.4.0",
|
||||
"bcrypt": "^5.0.0",
|
||||
"chalk": "^4.1.0",
|
||||
"chart.js": "^2.9.3",
|
||||
"classnames": "^2.2.6",
|
||||
"cookie": "^0.4.1",
|
||||
@@ -54,11 +50,10 @@
|
||||
"formik": "^2.1.5",
|
||||
"geolite2-redist": "^1.0.7",
|
||||
"is-localhost-ip": "^1.4.0",
|
||||
"jose": "^1.27.3",
|
||||
"jose": "^1.28.0",
|
||||
"maxmind": "^4.1.4",
|
||||
"moment-timezone": "^0.5.31",
|
||||
"next": "9.5.1",
|
||||
"node-fetch": "^2.6.0",
|
||||
"next": "9.5.2",
|
||||
"promise-polyfill": "^8.1.3",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
@@ -72,13 +67,11 @@
|
||||
"request-ip": "^2.1.3",
|
||||
"tinycolor2": "^1.4.1",
|
||||
"unfetch": "^4.1.0",
|
||||
"uuid": "^8.3.0",
|
||||
"yargs": "^15.4.1"
|
||||
"uuid": "^8.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@prisma/cli": "2.4.1",
|
||||
"@rollup/plugin-buble": "^0.21.3",
|
||||
"@rollup/plugin-commonjs": "^14.0.0",
|
||||
"@rollup/plugin-node-resolve": "^8.4.0",
|
||||
"@rollup/plugin-replace": "^2.3.3",
|
||||
"@svgr/webpack": "^5.4.0",
|
||||
@@ -90,7 +83,6 @@
|
||||
"eslint-plugin-react": "^7.20.5",
|
||||
"eslint-plugin-react-hooks": "^4.0.4",
|
||||
"husky": "^4.2.5",
|
||||
"less": "^3.12.2",
|
||||
"lint-staged": "^10.2.9",
|
||||
"postcss-flexbugs-fixes": "^4.2.1",
|
||||
"postcss-import": "^12.0.1",
|
||||
@@ -99,7 +91,7 @@
|
||||
"prettier-eslint": "^11.0.0",
|
||||
"rollup": "^2.23.1",
|
||||
"rollup-plugin-hashbang": "^2.2.2",
|
||||
"rollup-plugin-terser": "^6.1.0",
|
||||
"rollup-plugin-terser": "^7.0.0",
|
||||
"stylelint": "^13.6.0",
|
||||
"stylelint-config-css-modules": "^2.2.0",
|
||||
"stylelint-config-prettier": "^8.0.1",
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
!function(){"use strict";function e(e){var t=this.constructor;return this.then((function(n){return t.resolve(e()).then((function(){return n}))}),(function(n){return t.resolve(e()).then((function(){return t.reject(n)}))}))}var t=setTimeout;function n(e){return Boolean(e&&void 0!==e.length)}function r(){}function o(e){if(!(this instanceof o))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],f(e,this)}function i(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,o._immediateFn((function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var r;try{r=n(e._value)}catch(e){return void s(t.promise,e)}u(t.promise,r)}else(1===e._state?u:s)(t.promise,e._value)}))):e._deferreds.push(t)}function u(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof o)return e._state=3,e._value=t,void a(e);if("function"==typeof n)return void f((r=n,i=t,function(){r.apply(i,arguments)}),e)}e._state=1,e._value=t,a(e)}catch(t){s(e,t)}var r,i}function s(e,t){e._state=2,e._value=t,a(e)}function a(e){2===e._state&&0===e._deferreds.length&&o._immediateFn((function(){e._handled||o._unhandledRejectionFn(e._value)}));for(var t=0,n=e._deferreds.length;t<n;t++)i(e,e._deferreds[t]);e._deferreds=null}function c(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function f(e,t){var n=!1;try{e((function(e){n||(n=!0,u(t,e))}),(function(e){n||(n=!0,s(t,e))}))}catch(e){if(n)return;n=!0,s(t,e)}}o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,t){var n=new this.constructor(r);return i(this,new c(e,t,n)),n},o.prototype["finally"]=e,o.all=function(e){return new o((function(t,r){if(!n(e))return r(new TypeError("Promise.all accepts an array"));var o=Array.prototype.slice.call(e);if(0===o.length)return t([]);var i=o.length;function u(e,n){try{if(n&&("object"==typeof n||"function"==typeof n)){var s=n.then;if("function"==typeof s)return void s.call(n,(function(t){u(e,t)}),r)}o[e]=n,0==--i&&t(o)}catch(e){r(e)}}for(var s=0;s<o.length;s++)u(s,o[s])}))},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o((function(t){t(e)}))},o.reject=function(e){return new o((function(t,n){n(e)}))},o.race=function(e){return new o((function(t,r){if(!n(e))return r(new TypeError("Promise.race accepts an array"));for(var i=0,u=e.length;i<u;i++)o.resolve(e[i]).then(t,r)}))},o._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){t(e,0)},o._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}();"Promise"in l?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=e):l["Promise"]=o,self.fetch||(self.fetch=function(e,t){return t=t||{},new Promise((function(n,r){var o=new XMLHttpRequest,i=[],u=[],s={},a=function(){return{ok:2==(o.status/100|0),statusText:o.statusText,status:o.status,url:o.responseURL,text:function(){return Promise.resolve(o.responseText)},json:function(){return Promise.resolve(JSON.parse(o.responseText))},blob:function(){return Promise.resolve(new Blob([o.response]))},clone:a,headers:{keys:function(){return i},entries:function(){return u},get:function(e){return s[e.toLowerCase()]},has:function(e){return e.toLowerCase()in s}}}};for(var c in o.open(t.method||"get",e,!0),o.onload=function(){o.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,n){i.push(t=t.toLowerCase()),u.push([t,n]),s[t]=s[t]?s[t]+","+n:n})),n(a())},o.onerror=r,o.withCredentials="include"==t.credentials,t.headers)o.setRequestHeader(c,t.headers[c]);o.send(t.body||null)}))});var h=function(e,t){return function(e,t,n){return fetch(t,{method:e,cache:"no-cache",headers:{Accept:"application/json","Content-Type":"application/json"},body:n}).then((function(t){return t.ok?t.json():["post","put","delete"].includes(e)?t.text().then((function(e){return{ok:t.ok,status:t.status,message:e}})):null}))}("post",e,JSON.stringify(t))},p=function(e,t,n){var r=e[t];return function(){for(var t=[],o=arguments.length;o--;)t[o]=arguments[o];return n.apply(null,t),r.apply(e,t)}};!function(e,t){var n=e.screen,r=n.width,o=n.height,i=e.navigator.language,u=e.location,s=u.hostname,a=u.pathname,c=u.search,f=e.localStorage,l=e.document,d=e.history,v=l.querySelector("script[data-website-id]"),y=v&&v.getAttribute("data-website-id"),m=new URL(v.src).origin,w=r+"x"+o,_=[],g=""+a+c,b=l.referrer,j=function(e,n){var r={session:f.getItem(t),url:g,referrer:b,website:y,hostname:s,screen:w,language:i};return n&&Object.keys(n).forEaLine truncated
|
||||
!function(){"use strict";function e(e){var t=this.constructor;return this.then((function(n){return t.resolve(e()).then((function(){return n}))}),(function(n){return t.resolve(e()).then((function(){return t.reject(n)}))}))}var t=setTimeout;function n(e){return Boolean(e&&void 0!==e.length)}function r(){}function o(e){if(!(this instanceof o))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],f(e,this)}function i(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,o._immediateFn((function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var r;try{r=n(e._value)}catch(e){return void s(t.promise,e)}u(t.promise,r)}else(1===e._state?u:s)(t.promise,e._value)}))):e._deferreds.push(t)}function u(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof o)return e._state=3,e._value=t,void a(e);if("function"==typeof n)return void f((r=n,i=t,function(){r.apply(i,arguments)}),e)}e._state=1,e._value=t,a(e)}catch(t){s(e,t)}var r,i}function s(e,t){e._state=2,e._value=t,a(e)}function a(e){2===e._state&&0===e._deferreds.length&&o._immediateFn((function(){e._handled||o._unhandledRejectionFn(e._value)}));for(var t=0,n=e._deferreds.length;t<n;t++)i(e,e._deferreds[t]);e._deferreds=null}function c(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function f(e,t){var n=!1;try{e((function(e){n||(n=!0,u(t,e))}),(function(e){n||(n=!0,s(t,e))}))}catch(e){if(n)return;n=!0,s(t,e)}}o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,t){var n=new this.constructor(r);return i(this,new c(e,t,n)),n},o.prototype["finally"]=e,o.all=function(e){return new o((function(t,r){if(!n(e))return r(new TypeError("Promise.all accepts an array"));var o=Array.prototype.slice.call(e);if(0===o.length)return t([]);var i=o.length;function u(e,n){try{if(n&&("object"==typeof n||"function"==typeof n)){var s=n.then;if("function"==typeof s)return void s.call(n,(function(t){u(e,t)}),r)}o[e]=n,0==--i&&t(o)}catch(e){r(e)}}for(var s=0;s<o.length;s++)u(s,o[s])}))},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o((function(t){t(e)}))},o.reject=function(e){return new o((function(t,n){n(e)}))},o.race=function(e){return new o((function(t,r){if(!n(e))return r(new TypeError("Promise.race accepts an array"));for(var i=0,u=e.length;i<u;i++)o.resolve(e[i]).then(t,r)}))},o._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){t(e,0)},o._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}();"Promise"in l?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=e):l["Promise"]=o,self.fetch||(self.fetch=function(e,t){return t=t||{},new Promise((function(n,r){var o=new XMLHttpRequest,i=[],u=[],s={},a=function(){return{ok:2==(o.status/100|0),statusText:o.statusText,status:o.status,url:o.responseURL,text:function(){return Promise.resolve(o.responseText)},json:function(){return Promise.resolve(JSON.parse(o.responseText))},blob:function(){return Promise.resolve(new Blob([o.response]))},clone:a,headers:{keys:function(){return i},entries:function(){return u},get:function(e){return s[e.toLowerCase()]},has:function(e){return e.toLowerCase()in s}}}};for(var c in o.open(t.method||"get",e,!0),o.onload=function(){o.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,n){i.push(t=t.toLowerCase()),u.push([t,n]),s[t]=s[t]?s[t]+","+n:n})),n(a())},o.onerror=r,o.withCredentials="include"==t.credentials,t.headers)o.setRequestHeader(c,t.headers[c]);o.send(t.body||null)}))});var h=function(e,t){return function(e,t,n){return fetch(t,{method:e,cache:"no-cache",headers:{Accept:"application/json","Content-Type":"application/json"},body:n}).then((function(t){return t.ok?t.json():["post","put","delete"].includes(e)?t.text():null}))}("post",e,JSON.stringify(t))},p=function(e,t,n){var r=e[t];return function(){for(var t=[],o=arguments.length;o--;)t[o]=arguments[o];return n.apply(null,t),r.apply(e,t)}};!function(e,t){var n=e.screen,r=n.width,o=n.height,i=e.navigator.language,u=e.location,s=u.hostname,a=u.pathname,c=u.search,f=e.localStorage,l=e.document,d=e.history,v=l.querySelector("script[data-website-id]"),y=v&&v.getAttribute("data-website-id"),m=new URL(v.src).origin,w=r+"x"+o,_=[],g=""+a+c,b=l.referrer,j=function(e,n){var r={session:f.getItem(t),url:g,referrer:b,website:y,hostname:s,screen:w,language:i};return n&&Object.keys(n).forEach((function(e){r[e]=n[e]})),h(m+"/api/collect",{type:e,payloadLine truncated
|
||||
@@ -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 (
|
||||
user_id int unsigned not null auto_increment primary key,
|
||||
username varchar(255) unique not null,
|
||||
@@ -55,6 +61,8 @@ create table event (
|
||||
foreign key (session_id) references session(session_id) on delete cascade
|
||||
) 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_website_id_idx on session(website_id);
|
||||
|
||||
|
||||
@@ -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 (
|
||||
user_id serial primary key,
|
||||
username varchar(255) unique not null,
|
||||
@@ -49,6 +55,8 @@ create table event (
|
||||
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_website_id_idx on session(website_id);
|
||||
|
||||
|
||||
Reference in new issue
Block a user