Merge branch 'dev' into brian/um-22-query-folder-structure

This commit is contained in:
Brian Cao 2022-07-12 22:34:05 -07:00
commit 9803d4b5ee
14 changed files with 1281 additions and 1146 deletions

View File

@ -9,7 +9,7 @@ CREATE TABLE `account` (
UNIQUE INDEX `username`(`username`),
PRIMARY KEY (`user_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `event` (
@ -25,7 +25,7 @@ CREATE TABLE `event` (
INDEX `event_session_id_idx`(`session_id`),
INDEX `event_website_id_idx`(`website_id`),
PRIMARY KEY (`event_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `pageview` (
@ -42,7 +42,7 @@ CREATE TABLE `pageview` (
INDEX `pageview_website_id_idx`(`website_id`),
INDEX `pageview_website_id_session_id_created_at_idx`(`website_id`, `session_id`, `created_at`),
PRIMARY KEY (`view_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `session` (
@ -62,7 +62,7 @@ CREATE TABLE `session` (
INDEX `session_created_at_idx`(`created_at`),
INDEX `session_website_id_idx`(`website_id`),
PRIMARY KEY (`session_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `website` (
@ -78,7 +78,7 @@ CREATE TABLE `website` (
UNIQUE INDEX `share_id`(`share_id`),
INDEX `website_user_id_idx`(`user_id`),
PRIMARY KEY (`website_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `event` ADD CONSTRAINT `event_ibfk_2` FOREIGN KEY (`session_id`) REFERENCES `session`(`session_id`) ON DELETE CASCADE ON UPDATE NO ACTION;

View File

@ -4,9 +4,9 @@
"label.add-website": "Tilføj hjemmeside",
"label.administrator": "Administrator",
"label.all": "Alle",
"label.all-events": "All events",
"label.all-time": "All time",
"label.all-websites": "Alle websites",
"label.all-events": "Alle hændelser",
"label.all-time": "Altid",
"label.all-websites": "Alle hjemmesider",
"label.back": "Tilbage",
"label.cancel": "Afvis",
"label.change-password": "Skift adgangskode",
@ -28,30 +28,30 @@
"label.enable-share-url": "Aktivér delings-URL",
"label.invalid": "Ugyldig",
"label.invalid-domain": "Ugyldigt domæne",
"label.language": "Language",
"label.language": "Sprog",
"label.last-days": "Sidste {x} dage",
"label.last-hours": "Sidste {x} timer",
"label.logged-in-as": "Loggede ind som {username}",
"label.logged-in-as": "Logget ind som {username}",
"label.login": "Log ind",
"label.logout": "Log ud",
"label.more": "Mere",
"label.name": "Navn",
"label.new-password": "Ny adgangskode",
"label.owner": "Owner",
"label.owner": "Ejer",
"label.password": "Adgangskode",
"label.passwords-dont-match": "Adgangskoder matcher ikke",
"label.passwords-dont-match": "Adgangskoderne matcher ikke",
"label.profile": "Profil",
"label.realtime": "Realtid",
"label.realtime-logs": "Realtid logs",
"label.refresh": "Opdater",
"label.required": "Påkrævet",
"label.reset": "Reset",
"label.reset-website": "Reset statistics",
"label.reset": "Nulstil",
"label.reset-website": "Nulstil statistikker",
"label.save": "Gem",
"label.settings": "Indstillinger",
"label.share-url": "Del URL",
"label.single-day": "Enkelt dag",
"label.theme": "Theme",
"label.theme": "Tema",
"label.this-month": "Denne måned",
"label.this-week": "Denne uge",
"label.this-year": "Dette år",
@ -64,7 +64,7 @@
"label.websites": "Hjemmesider",
"message.active-users": "{x} nuværende {x, plural, one {bruger} other {brugere}}",
"message.confirm-delete": "Er du sikker på at du vil slette {target}?",
"message.confirm-reset": "Are your sure you want to reset {target}'s statistics?",
"message.confirm-reset": "Er du sikker på at du ville nulstille {target}'s statistikker?",
"message.copied": "Kopieret!",
"message.delete-warning": "Alle tilknyttede data slettes også.",
"message.failure": "Noget gik galt.",
@ -75,14 +75,14 @@
"message.log.visitor": "Besøgende fra {country} bruger {browser} på {os} {device}",
"message.new-version-available": "Ny udgave af Umami {version} er tilgængelig!",
"message.no-data-available": "Ingen data tilgængelig.",
"message.no-websites-configured": "Du har ikke konfigureret nogen websteder.",
"message.no-websites-configured": "Du har ikke konfigureret nogen hjemmesider.",
"message.page-not-found": "Side ikke fundet.",
"message.powered-by": "Drevet af {name}",
"message.reset-warning": "All statistics for this website will be deleted, but your tracking code will remain intact.",
"message.reset-warning": "Alle statistikker for denne hjemmeside ville blive slettet, men sporingskode ville forblive intakt.",
"message.save-success": "Gemt!",
"message.share-url": "Dette er den offentligt delings-URL til {target}.",
"message.toggle-charts": "Toggle charts",
"message.track-stats": "For at spore statistik for {target} skal du placere følgende kode i {head} sektionen på dit websted.",
"message.share-url": "Dette er den offentlige delings-URL til {target}.",
"message.toggle-charts": "Ændre graf",
"message.track-stats": "For at spore statistik for {target} skal du placere følgende kode i {head} sektionen på din hjemmeside.",
"message.type-delete": "Skriv {delete} i boksen nedenfor, for at bekræfte.",
"message.type-reset": "Skriv {reset} i boksen nedenfor, for at bekræfte.",
"metrics.actions": "Handlinger",
@ -99,7 +99,7 @@
"metrics.filter.combined": "Kombineret",
"metrics.filter.domain-only": "Kun domæne",
"metrics.filter.raw": "Rå",
"metrics.languages": "Languages",
"metrics.languages": "Sprog",
"metrics.operating-systems": "Operativsystemer",
"metrics.page-views": "Sidevisninger",
"metrics.pages": "Sider",

View File

@ -5,7 +5,7 @@
"label.administrator": "Administrator",
"label.all": "Alles",
"label.all-events": "Alle gebeurtenissen",
"label.all-time": "All time",
"label.all-time": "Onbeperkt",
"label.all-websites": "Alle websites",
"label.back": "Terug",
"label.cancel": "Annuleren",
@ -28,7 +28,7 @@
"label.enable-share-url": "Sta delen via openbare URL toe",
"label.invalid": "Ongeldig",
"label.invalid-domain": "Ongeldig domein",
"label.language": "Language",
"label.language": "Taal",
"label.last-days": "Laatste {x} dagen",
"label.last-hours": "Laatste {x} uur",
"label.logged-in-as": "Ingelogd als {username}",
@ -37,7 +37,7 @@
"label.more": "Toon meer",
"label.name": "Naam",
"label.new-password": "Nieuw wachtwoord",
"label.owner": "Owner",
"label.owner": "Eigenaar",
"label.password": "Wachtwoord",
"label.passwords-dont-match": "Wachtwoorden komen niet overeen",
"label.profile": "Profiel",
@ -46,12 +46,12 @@
"label.refresh": "Vernieuwen",
"label.required": "Verplicht",
"label.reset": "Resetten",
"label.reset-website": "Reset statistics",
"label.reset-website": "Statistieken opnieuw instellen",
"label.save": "Opslaan",
"label.settings": "Instellingen",
"label.share-url": "URL delen",
"label.single-day": "Enkele dag",
"label.theme": "Theme",
"label.theme": "Thema",
"label.this-month": "Deze maand",
"label.this-week": "Deze week",
"label.this-year": "Dit jaar",
@ -64,7 +64,7 @@
"label.websites": "Websites",
"message.active-users": "{x} actieve {x, plural, one {bezoeker} other {bezoekers}}",
"message.confirm-delete": "Weet je zeker dat je {target} wilt verwijderen?",
"message.confirm-reset": "Are your sure you want to reset {target}'s statistics?",
"message.confirm-reset": "Weet je zeker dat je de statistieken van {target} opnieuw wilt instellen?",
"message.copied": "Gekopiëerd!",
"message.delete-warning": "Alle verwante gegezens zullen ook verwijderd worden.",
"message.failure": "Er is iets misgegaan.",
@ -81,7 +81,7 @@
"message.reset-warning": "All statistics for this website will be deleted, but your tracking code will remain intact.",
"message.save-success": "Opslaan succesvol.",
"message.share-url": "Met deze URL kan {target} openbaar gedeeld worden.",
"message.toggle-charts": "Toggle charts",
"message.toggle-charts": "Grafieken tonen/verbergen",
"message.track-stats": "Om statistieken voor {target} bij te houden, plaats je de volgende code in het {head} gedeelte van je website.",
"message.type-delete": "Type {delete} in onderstaande veld om dit te bevestigen.",
"message.type-reset": "Type {reset} in onderstaande veld om dit te bevestigen.",
@ -100,7 +100,7 @@
"metrics.filter.domain-only": "Alleen domein",
"metrics.filter.raw": "Ruw",
"metrics.languages": "Languages",
"metrics.operating-systems": "Besturingssysteem",
"metrics.operating-systems": "Besturingssystemen",
"metrics.page-views": "Paginaweergaven",
"metrics.pages": "Pagina's",
"metrics.referrers": "Verwijzers",

View File

@ -1,6 +1,10 @@
import { PrismaClient } from '@prisma/client';
import chalk from 'chalk';
BigInt.prototype.toJSON = function () {
return this.toString();
};
const options = {
log: [
{

View File

@ -14,24 +14,36 @@ export function getDatabase() {
return type;
}
export function getDateStringQuery(data, unit) {
const db = getDatabase();
if (db === POSTGRESQL) {
return `to_char(${data}, '${POSTGRESQL_DATE_FORMATS[unit]}')`;
}
if (db === MYSQL) {
return `DATE_FORMAT(${data}, '${MYSQL_DATE_FORMATS[unit]}')`;
}
}
export function getDateQuery(field, unit, timezone) {
const db = getDatabase();
if (db === POSTGRESQL) {
if (timezone) {
return `to_char(date_trunc('${unit}', ${field} at time zone '${timezone}'), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
return `date_trunc('${unit}', ${field} at time zone '${timezone}')`;
}
return `to_char(date_trunc('${unit}', ${field}), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
return `date_trunc('${unit}', ${field})`;
}
if (db === MYSQL) {
if (timezone) {
const tz = moment.tz(timezone).format('Z');
return `DATE_FORMAT(convert_tz(${field},'+00:00','${tz}'), '${MYSQL_DATE_FORMATS[unit]}')`;
return `convert_tz(${field},'+00:00','${tz}')`;
}
return `DATE_FORMAT(${field}, '${MYSQL_DATE_FORMATS[unit]}')`;
return `${field}`;
}
}

View File

@ -1,5 +1,23 @@
import { NextResponse } from 'next/server';
export const config = {
matcher: '/:path*',
};
function customCollectEndpoint(req) {
const collectEndpoint = process.env.COLLECT_API_ENDPOINT;
if (collectEndpoint) {
const url = req.nextUrl.clone();
const { pathname } = url;
if (pathname.endsWith(collectEndpoint)) {
url.pathname = '/api/collect';
return NextResponse.rewrite(url);
}
}
}
function customScriptName(req) {
const scriptName = process.env.TRACKER_SCRIPT_NAME;
@ -23,8 +41,8 @@ function forceSSL(req, res) {
return res;
}
export function middleware(req) {
const fns = [customScriptName];
export default function middleware(req) {
const fns = [customCollectEndpoint, customScriptName];
for (const fn of fns) {
const res = fn(req);

View File

@ -8,9 +8,7 @@ module.exports = {
updatesDisabled: process.env.DISABLE_UPDATES,
},
basePath: process.env.BASE_PATH,
experimental: {
outputStandalone: true,
},
output: 'standalone',
eslint: {
ignoreDuringBuilds: true,
},

View File

@ -79,7 +79,7 @@
"jose": "2.0.5",
"maxmind": "^4.3.6",
"moment-timezone": "^0.5.33",
"next": "12.1.0",
"next": "12.2.0",
"node-fetch": "^3.2.3",
"npm-run-all": "^4.1.5",
"prop-types": "^15.7.2",
@ -101,10 +101,11 @@
"devDependencies": {
"@formatjs/cli": "^4.2.29",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-replace": "^4.0.0",
"@svgr/webpack": "^6.2.1",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-next": "^12.0.1",
"eslint-config-next": "^12.2.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"extract-react-intl-messages": "^4.1.1",

View File

@ -38,7 +38,7 @@
"label.all-time": [
{
"type": 0,
"value": "All time"
"value": "Onbeperkt"
}
],
"label.all-websites": [
@ -176,7 +176,7 @@
"label.language": [
{
"type": 0,
"value": "Language"
"value": "Taal"
}
],
"label.last-days": [
@ -250,7 +250,7 @@
"label.owner": [
{
"type": 0,
"value": "Owner"
"value": "Eigenaar"
}
],
"label.password": [
@ -304,7 +304,7 @@
"label.reset-website": [
{
"type": 0,
"value": "Reset statistics"
"value": "Statistieken opnieuw instellen"
}
],
"label.save": [
@ -334,7 +334,7 @@
"label.theme": [
{
"type": 0,
"value": "Theme"
"value": "Thema"
}
],
"label.this-month": [
@ -448,7 +448,7 @@
"message.confirm-reset": [
{
"type": 0,
"value": "Are your sure you want to reset "
"value": "Weet je zeker dat je de statistieken van "
},
{
"type": 1,
@ -456,7 +456,7 @@
},
{
"type": 0,
"value": "'s statistics?"
"value": " opnieuw wilt instellen?"
}
],
"message.copied": [
@ -606,7 +606,7 @@
"message.toggle-charts": [
{
"type": 0,
"value": "Toggle charts"
"value": "Grafieken tonen/verbergen"
}
],
"message.track-stats": [
@ -752,7 +752,7 @@
"metrics.operating-systems": [
{
"type": 0,
"value": "Besturingssysteem"
"value": "Besturingssystemen"
}
],
"metrics.page-views": [

View File

@ -1,4 +1,5 @@
import buble from '@rollup/plugin-buble';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';
export default {
@ -7,5 +8,12 @@ export default {
file: 'public/umami.js',
format: 'iife',
},
plugins: [buble({ objectAssign: true }), terser({ compress: { evaluate: false } })],
plugins: [
replace({
'/api/collect': process.env.COLLECT_API_ENDPOINT || '/api/collect',
delimiters: ['', ''],
}),
buble({ objectAssign: true }),
terser({ compress: { evaluate: false } }),
],
};

View File

@ -1,11 +1,10 @@
require('dotenv').config();
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const chalk = require('chalk');
const spawn = require('cross-spawn');
const { execSync } = require('child_process');
let message = '';
const prisma = new PrismaClient();
function success(msg) {
console.log(chalk.greenBright(`${msg}`));
@ -59,7 +58,7 @@ async function run(cmd, args) {
async function checkMigrations() {
const output = await run('prisma', ['migrate', 'status']);
const missingMigrations = output.includes('Following migration have not yet been applied');
const missingMigrations = output.includes('have not yet been applied');
const notManaged = output.includes('The current database is not managed');
if (notManaged || missingMigrations) {
@ -82,7 +81,6 @@ async function checkMigrations() {
} finally {
await prisma.$disconnect();
if (err) {
console.log(message);
process.exit(1);
}
}

View File

@ -1,80 +1,102 @@
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;
-- CreateTable
CREATE TABLE `account` (
`user_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`username` VARCHAR(255) NOT NULL,
`password` VARCHAR(60) NOT NULL,
`is_admin` BOOLEAN NOT NULL DEFAULT false,
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
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;
UNIQUE INDEX `username`(`username`),
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_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;
-- CreateTable
CREATE TABLE `event` (
`event_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`website_id` INTEGER UNSIGNED NOT NULL,
`session_id` INTEGER UNSIGNED NOT NULL,
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
`url` VARCHAR(500) NOT NULL,
`event_type` VARCHAR(50) NOT NULL,
`event_value` VARCHAR(50) NOT NULL,
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;
INDEX `event_created_at_idx`(`created_at`),
INDEX `event_session_id_idx`(`session_id`),
INDEX `event_website_id_idx`(`website_id`),
PRIMARY KEY (`event_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_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;
-- CreateTable
CREATE TABLE `pageview` (
`view_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`website_id` INTEGER UNSIGNED NOT NULL,
`session_id` INTEGER UNSIGNED NOT NULL,
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
`url` VARCHAR(500) NOT NULL,
`referrer` VARCHAR(500) NULL,
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;
INDEX `pageview_created_at_idx`(`created_at`),
INDEX `pageview_session_id_idx`(`session_id`),
INDEX `pageview_website_id_created_at_idx`(`website_id`, `created_at`),
INDEX `pageview_website_id_idx`(`website_id`),
INDEX `pageview_website_id_session_id_created_at_idx`(`website_id`, `session_id`, `created_at`),
PRIMARY KEY (`view_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
create index website_user_id_idx on website(user_id);
-- CreateTable
CREATE TABLE `session` (
`session_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`session_uuid` VARCHAR(36) NOT NULL,
`website_id` INTEGER UNSIGNED NOT NULL,
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
`hostname` VARCHAR(100) NULL,
`browser` VARCHAR(20) NULL,
`os` VARCHAR(20) NULL,
`device` VARCHAR(20) NULL,
`screen` VARCHAR(11) NULL,
`language` VARCHAR(35) NULL,
`country` CHAR(2) NULL,
create index session_created_at_idx on session(created_at);
create index session_website_id_idx on session(website_id);
UNIQUE INDEX `session_uuid`(`session_uuid`),
INDEX `session_created_at_idx`(`created_at`),
INDEX `session_website_id_idx`(`website_id`),
PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
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);
-- CreateTable
CREATE TABLE `website` (
`website_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`website_uuid` VARCHAR(36) NOT NULL,
`user_id` INTEGER UNSIGNED NOT NULL,
`name` VARCHAR(100) NOT NULL,
`domain` VARCHAR(500) NULL,
`share_id` VARCHAR(64) NULL,
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
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);
UNIQUE INDEX `website_uuid`(`website_uuid`),
UNIQUE INDEX `share_id`(`share_id`),
INDEX `website_user_id_idx`(`user_id`),
PRIMARY KEY (`website_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
insert into account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
-- AddForeignKey
ALTER TABLE `event` ADD CONSTRAINT `event_ibfk_2` FOREIGN KEY (`session_id`) REFERENCES `session`(`session_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
-- AddForeignKey
ALTER TABLE `event` ADD CONSTRAINT `event_ibfk_1` FOREIGN KEY (`website_id`) REFERENCES `website`(`website_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
-- AddForeignKey
ALTER TABLE `pageview` ADD CONSTRAINT `pageview_ibfk_2` FOREIGN KEY (`session_id`) REFERENCES `session`(`session_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
-- AddForeignKey
ALTER TABLE `pageview` ADD CONSTRAINT `pageview_ibfk_1` FOREIGN KEY (`website_id`) REFERENCES `website`(`website_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
-- AddForeignKey
ALTER TABLE `session` ADD CONSTRAINT `session_ibfk_1` FOREIGN KEY (`website_id`) REFERENCES `website`(`website_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
-- AddForeignKey
ALTER TABLE `website` ADD CONSTRAINT `website_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`(`user_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
-- CreateAdminUser
INSERT INTO account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);

View File

@ -1,74 +1,132 @@
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;
-- CreateTable
CREATE TABLE "account" (
"user_id" SERIAL NOT NULL,
"username" VARCHAR(255) NOT NULL,
"password" VARCHAR(60) NOT NULL,
"is_admin" BOOLEAN NOT NULL DEFAULT false,
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
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
PRIMARY KEY ("user_id")
);
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
-- CreateTable
CREATE TABLE "event" (
"event_id" SERIAL NOT NULL,
"website_id" INTEGER NOT NULL,
"session_id" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
"url" VARCHAR(500) NOT NULL,
"event_type" VARCHAR(50) NOT NULL,
"event_value" VARCHAR(50) NOT NULL,
PRIMARY KEY ("event_id")
);
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)
-- CreateTable
CREATE TABLE "pageview" (
"view_id" SERIAL NOT NULL,
"website_id" INTEGER NOT NULL,
"session_id" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
"url" VARCHAR(500) NOT NULL,
"referrer" VARCHAR(500),
PRIMARY KEY ("view_id")
);
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)
-- CreateTable
CREATE TABLE "session" (
"session_id" SERIAL NOT NULL,
"session_uuid" UUID NOT NULL,
"website_id" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
"hostname" VARCHAR(100),
"browser" VARCHAR(20),
"os" VARCHAR(20),
"device" VARCHAR(20),
"screen" VARCHAR(11),
"language" VARCHAR(35),
"country" CHAR(2),
PRIMARY KEY ("session_id")
);
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
-- CreateTable
CREATE TABLE "website" (
"website_id" SERIAL NOT NULL,
"website_uuid" UUID NOT NULL,
"user_id" INTEGER NOT NULL,
"name" VARCHAR(100) NOT NULL,
"domain" VARCHAR(500),
"share_id" VARCHAR(64),
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ("website_id")
);
create index website_user_id_idx on website(user_id);
-- CreateIndex
CREATE UNIQUE INDEX "account.username_unique" ON "account"("username");
create index session_created_at_idx on session(created_at);
create index session_website_id_idx on session(website_id);
-- CreateIndex
CREATE INDEX "event_created_at_idx" ON "event"("created_at");
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);
-- CreateIndex
CREATE INDEX "event_session_id_idx" ON "event"("session_id");
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);
-- CreateIndex
CREATE INDEX "event_website_id_idx" ON "event"("website_id");
insert into account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
-- 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");
-- AddForeignKey
ALTER TABLE "event" ADD FOREIGN KEY ("session_id") REFERENCES "session"("session_id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "event" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "pageview" ADD FOREIGN KEY ("session_id") REFERENCES "session"("session_id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "pageview" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "session" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "website" ADD FOREIGN KEY ("user_id") REFERENCES "account"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
-- CreateAdminUser
INSERT INTO account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);

1940
yarn.lock

File diff suppressed because it is too large Load Diff