schema + docker cleanups
parent
ae7de014a6
commit
4a21d9e9d9
13
Dockerfile
13
Dockerfile
|
@ -1,22 +1,12 @@
|
|||
# Build image
|
||||
FROM node:16.2.0-alpine3.13 AS build
|
||||
ARG DATABASE_TYPE
|
||||
ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" \
|
||||
DATABASE_TYPE=$DATABASE_TYPE
|
||||
WORKDIR /build
|
||||
|
||||
RUN yarn config set --home enableTelemetry 0
|
||||
COPY package.json yarn.lock /build/
|
||||
|
||||
# Install only the production dependencies
|
||||
RUN yarn --production --frozen-lockfile
|
||||
|
||||
# Cache these modules for production
|
||||
RUN cp -R node_modules/ prod_node_modules/
|
||||
|
||||
# Install development dependencies
|
||||
RUN yarn --frozen-lockfile
|
||||
|
||||
COPY . /build
|
||||
RUN yarn next telemetry disable
|
||||
RUN yarn build
|
||||
|
@ -35,7 +25,4 @@ COPY --from=build /build/yarn.lock /build/package.json ./
|
|||
COPY --from=build /build/.next ./.next
|
||||
COPY --from=build /build/public ./public
|
||||
|
||||
USER node
|
||||
|
||||
EXPOSE 3000
|
||||
CMD ["yarn", "start"]
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
---
|
||||
version: '3'
|
||||
services:
|
||||
umami:
|
||||
build: .
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- 50001:3000
|
||||
environment:
|
||||
DATABASE_URL: sqlite://umami:umami@db:5432/umami
|
||||
DATABASE_TYPE: sqlite
|
||||
HASH_SALT: xSSHW4A2w0e3vxLUp46XL9OzCGKvxEnA
|
||||
depends_on:
|
||||
- db
|
||||
# depends_on:
|
||||
# - db
|
||||
# db:
|
||||
# image: postgres:13.3-alpine
|
||||
# environment:
|
||||
|
@ -20,5 +17,5 @@ services:
|
|||
# volumes:
|
||||
# - ./sql/schema.postgresql.sql:/docker-entrypoint-initdb.d/schema.postgresql.sql:ro
|
||||
# - umami-db-data:/var/lib/postgresql/data
|
||||
volumes:
|
||||
umami-db-data:
|
||||
# volumes:
|
||||
# umami-db-data:
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "account" (
|
||||
"user_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"username" TEXT NOT NULL,
|
||||
"password" TEXT NOT NULL,
|
||||
"is_admin" BOOLEAN NOT NULL DEFAULT false,
|
||||
"created_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "event" (
|
||||
"event_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"website_id" INTEGER NOT NULL,
|
||||
"session_id" INTEGER NOT NULL,
|
||||
"created_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
"url" TEXT NOT NULL,
|
||||
"event_type" TEXT NOT NULL,
|
||||
"event_value" TEXT NOT NULL,
|
||||
FOREIGN KEY ("session_id") REFERENCES "session" ("session_id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY ("website_id") REFERENCES "website" ("website_id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "pageview" (
|
||||
"view_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"website_id" INTEGER NOT NULL,
|
||||
"session_id" INTEGER NOT NULL,
|
||||
"created_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
"url" TEXT NOT NULL,
|
||||
"referrer" TEXT,
|
||||
FOREIGN KEY ("session_id") REFERENCES "session" ("session_id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY ("website_id") REFERENCES "website" ("website_id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "session" (
|
||||
"session_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"session_uuid" TEXT NOT NULL,
|
||||
"website_id" INTEGER NOT NULL,
|
||||
"created_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
"hostname" TEXT,
|
||||
"browser" TEXT,
|
||||
"os" TEXT,
|
||||
"device" TEXT,
|
||||
"screen" TEXT,
|
||||
"language" TEXT,
|
||||
"country" TEXT,
|
||||
FOREIGN KEY ("website_id") REFERENCES "website" ("website_id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "website" (
|
||||
"website_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"website_uuid" TEXT NOT NULL,
|
||||
"user_id" INTEGER NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"domain" TEXT,
|
||||
"share_id" TEXT,
|
||||
"created_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("user_id") REFERENCES "account" ("user_id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "account.username_unique" ON "account"("username");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "event_created_at_idx" ON "event"("created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "event_session_id_idx" ON "event"("session_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "event_website_id_idx" ON "event"("website_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_created_at_idx" ON "pageview"("created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_session_id_idx" ON "pageview"("session_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_website_id_created_at_idx" ON "pageview"("website_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_website_id_idx" ON "pageview"("website_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_website_id_session_id_created_at_idx" ON "pageview"("website_id", "session_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "session.session_uuid_unique" ON "session"("session_uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "session_created_at_idx" ON "session"("created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "session_website_id_idx" ON "session"("website_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "website.website_uuid_unique" ON "website"("website_uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "website.share_id_unique" ON "website"("share_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "website_user_id_idx" ON "website"("user_id");
|
||||
--
|
||||
-- TODO: move this insert into seeder
|
||||
insert into account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
|
|
@ -0,0 +1,3 @@
|
|||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "sqlite"
|
|
@ -1,87 +0,0 @@
|
|||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model account {
|
||||
user_id Int @id @default(autoincrement()) @db.UnsignedInt
|
||||
username String @unique @db.VarChar(255)
|
||||
password String @db.VarChar(60)
|
||||
is_admin Boolean @default(false)
|
||||
created_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
website website[]
|
||||
}
|
||||
|
||||
model event {
|
||||
event_id Int @id @default(autoincrement()) @db.UnsignedInt
|
||||
website_id Int @db.UnsignedInt
|
||||
session_id Int @db.UnsignedInt
|
||||
created_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
url String @db.VarChar(500)
|
||||
event_type String @db.VarChar(50)
|
||||
event_value String @db.VarChar(50)
|
||||
session session @relation(fields: [session_id], references: [session_id])
|
||||
website website @relation(fields: [website_id], references: [website_id])
|
||||
|
||||
@@index([created_at], name: "event_created_at_idx")
|
||||
@@index([session_id], name: "event_session_id_idx")
|
||||
@@index([website_id], name: "event_website_id_idx")
|
||||
}
|
||||
|
||||
model pageview {
|
||||
view_id Int @id @default(autoincrement()) @db.UnsignedInt
|
||||
website_id Int @db.UnsignedInt
|
||||
session_id Int @db.UnsignedInt
|
||||
created_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
url String @db.VarChar(500)
|
||||
referrer String? @db.VarChar(500)
|
||||
session session @relation(fields: [session_id], references: [session_id])
|
||||
website website @relation(fields: [website_id], references: [website_id])
|
||||
|
||||
@@index([created_at], name: "pageview_created_at_idx")
|
||||
@@index([session_id], name: "pageview_session_id_idx")
|
||||
@@index([website_id, created_at], name: "pageview_website_id_created_at_idx")
|
||||
@@index([website_id], name: "pageview_website_id_idx")
|
||||
@@index([website_id, session_id, created_at], name: "pageview_website_id_session_id_created_at_idx")
|
||||
}
|
||||
|
||||
model session {
|
||||
session_id Int @id @default(autoincrement()) @db.UnsignedInt
|
||||
session_uuid String @unique @db.VarChar(36)
|
||||
website_id Int @db.UnsignedInt
|
||||
created_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
hostname String? @db.VarChar(100)
|
||||
browser String? @db.VarChar(20)
|
||||
os String? @db.VarChar(20)
|
||||
device String? @db.VarChar(20)
|
||||
screen String? @db.VarChar(11)
|
||||
language String? @db.VarChar(35)
|
||||
country String? @db.Char(2)
|
||||
website website @relation(fields: [website_id], references: [website_id])
|
||||
event event[]
|
||||
pageview pageview[]
|
||||
|
||||
@@index([created_at], name: "session_created_at_idx")
|
||||
@@index([website_id], name: "session_website_id_idx")
|
||||
}
|
||||
|
||||
model website {
|
||||
website_id Int @id @default(autoincrement()) @db.UnsignedInt
|
||||
website_uuid String @unique @db.VarChar(36)
|
||||
user_id Int @db.UnsignedInt
|
||||
name String @db.VarChar(100)
|
||||
domain String? @db.VarChar(500)
|
||||
share_id String? @unique @db.VarChar(64)
|
||||
created_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
account account @relation(fields: [user_id], references: [user_id])
|
||||
event event[]
|
||||
pageview pageview[]
|
||||
session session[]
|
||||
|
||||
@@index([user_id], name: "website_user_id_idx")
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
require('dotenv').config();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function getDatabase() {
|
||||
const type =
|
||||
process.env.DATABASE_TYPE ||
|
||||
(process.env.DATABASE_URL && process.env.DATABASE_URL.split(':')[0]);
|
||||
|
||||
if (type === 'postgres') {
|
||||
return 'postgresql';
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
const databaseType = getDatabase();
|
||||
|
||||
if (!databaseType || !['mysql', 'postgresql'].includes(databaseType)) {
|
||||
throw new Error('Missing or invalid database');
|
||||
}
|
||||
|
||||
console.log(`Database type detected: ${databaseType}`);
|
||||
|
||||
const src = path.resolve(__dirname, `../prisma/schema.${databaseType}.prisma`);
|
||||
const dest = path.resolve(__dirname, '../prisma/schema.prisma');
|
||||
|
||||
fs.copyFileSync(src, dest);
|
||||
|
||||
console.log(`Copied ${src} to ${dest}`);
|
|
@ -1,3 +1,3 @@
|
|||
const cli = require('next/dist/cli/next-start');
|
||||
|
||||
cli.nextStart(['-p', process.env.PORT || 3000, '-H', process.env.HOSTNAME || '0.0.0.0']);
|
||||
cli.nextStart(['-p', process.env.PORT || 50001, '-H', process.env.HOSTNAME || '0.0.0.0']);
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
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,
|
||||
password varchar(60) not null,
|
||||
is_admin bool not null default false,
|
||||
created_at timestamp default current_timestamp,
|
||||
updated_at timestamp default current_timestamp
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
|
||||
create table website (
|
||||
website_id int unsigned not null auto_increment primary key,
|
||||
website_uuid varchar(36) unique not null,
|
||||
user_id int unsigned not null,
|
||||
name varchar(100) not null,
|
||||
domain varchar(500),
|
||||
share_id varchar(64) unique,
|
||||
created_at timestamp default current_timestamp,
|
||||
foreign key (user_id) references account(user_id) on delete cascade
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
|
||||
create table session (
|
||||
session_id int unsigned not null auto_increment primary key,
|
||||
session_uuid varchar(36) unique not null,
|
||||
website_id int unsigned not null references website(website_id) on delete cascade,
|
||||
created_at timestamp default current_timestamp,
|
||||
hostname varchar(100),
|
||||
browser varchar(20),
|
||||
os varchar(20),
|
||||
device varchar(20),
|
||||
screen varchar(11),
|
||||
language varchar(35),
|
||||
country char(2),
|
||||
foreign key (website_id) references website(website_id) on delete cascade
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
|
||||
create table pageview (
|
||||
view_id int unsigned not null auto_increment primary key,
|
||||
website_id int unsigned not null,
|
||||
session_id int unsigned not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
url varchar(500) not null,
|
||||
referrer varchar(500),
|
||||
foreign key (website_id) references website(website_id) on delete cascade,
|
||||
foreign key (session_id) references session(session_id) on delete cascade
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
|
||||
create table event (
|
||||
event_id int unsigned not null auto_increment primary key,
|
||||
website_id int unsigned not null,
|
||||
session_id int unsigned not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
url varchar(500) not null,
|
||||
event_type varchar(50) not null,
|
||||
event_value varchar(50) not null,
|
||||
foreign key (website_id) references website(website_id) on delete cascade,
|
||||
foreign key (session_id) references session(session_id) on delete cascade
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
|
||||
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);
|
||||
|
||||
create index pageview_created_at_idx on pageview(created_at);
|
||||
create index pageview_website_id_idx on pageview(website_id);
|
||||
create index pageview_session_id_idx on pageview(session_id);
|
||||
create index pageview_website_id_created_at_idx on pageview(website_id, created_at);
|
||||
create index pageview_website_id_session_id_created_at_idx on pageview(website_id, session_id, created_at);
|
||||
|
||||
create index event_created_at_idx on event(created_at);
|
||||
create index event_website_id_idx on event(website_id);
|
||||
create index event_session_id_idx on event(session_id);
|
||||
|
||||
insert into account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
|
|
@ -1,74 +0,0 @@
|
|||
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,
|
||||
password varchar(60) not null,
|
||||
is_admin bool not null default false,
|
||||
created_at timestamp with time zone default current_timestamp,
|
||||
updated_at timestamp with time zone default current_timestamp
|
||||
);
|
||||
|
||||
create table website (
|
||||
website_id serial primary key,
|
||||
website_uuid uuid unique not null,
|
||||
user_id int not null references account(user_id) on delete cascade,
|
||||
name varchar(100) not null,
|
||||
domain varchar(500),
|
||||
share_id varchar(64) unique,
|
||||
created_at timestamp with time zone default current_timestamp
|
||||
);
|
||||
|
||||
create table session (
|
||||
session_id serial primary key,
|
||||
session_uuid uuid unique not null,
|
||||
website_id int not null references website(website_id) on delete cascade,
|
||||
created_at timestamp with time zone default current_timestamp,
|
||||
hostname varchar(100),
|
||||
browser varchar(20),
|
||||
os varchar(20),
|
||||
device varchar(20),
|
||||
screen varchar(11),
|
||||
language varchar(35),
|
||||
country char(2)
|
||||
);
|
||||
|
||||
create table pageview (
|
||||
view_id serial primary key,
|
||||
website_id int not null references website(website_id) on delete cascade,
|
||||
session_id int not null references session(session_id) on delete cascade,
|
||||
created_at timestamp with time zone default current_timestamp,
|
||||
url varchar(500) not null,
|
||||
referrer varchar(500)
|
||||
);
|
||||
|
||||
create table event (
|
||||
event_id serial primary key,
|
||||
website_id int not null references website(website_id) on delete cascade,
|
||||
session_id int not null references session(session_id) on delete cascade,
|
||||
created_at timestamp with time zone default current_timestamp,
|
||||
url varchar(500) not null,
|
||||
event_type 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_website_id_idx on session(website_id);
|
||||
|
||||
create index pageview_created_at_idx on pageview(created_at);
|
||||
create index pageview_website_id_idx on pageview(website_id);
|
||||
create index pageview_session_id_idx on pageview(session_id);
|
||||
create index pageview_website_id_created_at_idx on pageview(website_id, created_at);
|
||||
create index pageview_website_id_session_id_created_at_idx on pageview(website_id, session_id, created_at);
|
||||
|
||||
create index event_created_at_idx on event(created_at);
|
||||
create index event_website_id_idx on event(website_id);
|
||||
create index event_session_id_idx on event(session_id);
|
||||
|
||||
insert into account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
|
Loading…
Reference in New Issue