Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
squash 01_init postgresql
Francis Caof984d80c428b
diff --git a/db/postgresql/migrations/01_init/migration.sql b/db/postgresql/migrations/01_init/migration.sqlindex 578e6f9c3..bd61e4575 100644--- a/db/postgresql/migrations/01_init/migration.sql+++ b/db/postgresql/migrations/01_init/migration.sql@@ -1,6 +1,3 @@--- CreateExtension-CREATE EXTENSION IF NOT EXISTS "pgcrypto";--- CreateTableCREATE TABLE "user" ("user_id" UUID NOT NULL,@@ -25,6 +22,9 @@ CREATE TABLE "session" ("screen" VARCHAR(11),"language" VARCHAR(35),"country" CHAR(2),+ "subdivision1" CHAR(3),+ "subdivision2" VARCHAR(50),+ "city" VARCHAR(50),"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,CONSTRAINT "session_pkey" PRIMARY KEY ("session_id")@@ -35,10 +35,9 @@ CREATE TABLE "website" ("website_id" UUID NOT NULL,"name" VARCHAR(100) NOT NULL,"domain" VARCHAR(500),- "share_id" VARCHAR(64),- "rev_id" INTEGER NOT NULL DEFAULT 0,+ "share_id" VARCHAR(50),+ "reset_at" TIMESTAMPTZ(6),"user_id" UUID,- "team_id" UUID,"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,"updated_at" TIMESTAMPTZ(6),"deleted_at" TIMESTAMPTZ(6),@@ -52,23 +51,40 @@ CREATE TABLE "website_event" ("website_id" UUID NOT NULL,"session_id" UUID NOT NULL,"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,- "url" VARCHAR(500) NOT NULL,- "referrer" VARCHAR(500),+ "url_path" VARCHAR(500) NOT NULL,+ "url_query" VARCHAR(500),+ "referrer_path" VARCHAR(500),+ "referrer_query" VARCHAR(500),+ "referrer_domain" VARCHAR(500),+ "page_title" VARCHAR(500),"event_type" INTEGER NOT NULL DEFAULT 1,"event_name" VARCHAR(50),- "event_data" JSONB,CONSTRAINT "website_event_pkey" PRIMARY KEY ("event_id"));+-- CreateTable+CREATE TABLE "event_data" (+ "event_id" UUID NOT NULL,+ "website_id" UUID NOT NULL,+ "website_event_id" UUID NOT NULL,+ "event_key" VARCHAR(500) NOT NULL,+ "event_string_value" VARCHAR(500),+ "event_numeric_value" DECIMAL(19,4),+ "event_date_value" TIMESTAMPTZ(6),+ "event_data_type" INTEGER NOT NULL,+ "created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,++ CONSTRAINT "event_data_pkey" PRIMARY KEY ("event_id")+);+-- CreateTableCREATE TABLE "team" ("team_id" UUID NOT NULL,"name" VARCHAR(50) NOT NULL,- "user_id" UUID NOT NULL,+ "access_code" VARCHAR(50),"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,"updated_at" TIMESTAMPTZ(6),- "deleted_at" TIMESTAMPTZ(6),CONSTRAINT "team_pkey" PRIMARY KEY ("team_id"));@@ -81,11 +97,20 @@ CREATE TABLE "team_user" ("role" VARCHAR(50) NOT NULL,"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,"updated_at" TIMESTAMPTZ(6),- "deleted_at" TIMESTAMPTZ(6),CONSTRAINT "team_user_pkey" PRIMARY KEY ("team_user_id"));+-- CreateTable+CREATE TABLE "team_website" (+ "team_website_id" UUID NOT NULL,+ "team_id" UUID NOT NULL,+ "website_id" UUID NOT NULL,+ "created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,++ CONSTRAINT "team_website_pkey" PRIMARY KEY ("team_website_id")+);+-- CreateIndexCREATE UNIQUE INDEX "user_user_id_key" ON "user"("user_id");@@ -107,6 +132,9 @@ CREATE UNIQUE INDEX "website_website_id_key" ON "website"("website_id");-- CreateIndexCREATE UNIQUE INDEX "website_share_id_key" ON "website"("share_id");+-- CreateIndex+CREATE INDEX "website_user_id_idx" ON "website"("user_id");+-- CreateIndexCREATE INDEX "website_created_at_idx" ON "website"("created_at");@@ -128,23 +156,41 @@ CREATE INDEX "website_event_website_id_created_at_idx" ON "website_event"("websi-- CreateIndexCREATE INDEX "website_event_website_id_session_id_created_at_idx" ON "website_event"("website_id", "session_id", "created_at");+-- CreateIndex+CREATE INDEX "event_data_created_at_idx" ON "event_data"("created_at");++-- CreateIndex+CREATE INDEX "event_data_website_id_idx" ON "event_data"("website_id");++-- CreateIndex+CREATE INDEX "event_data_website_event_id_idx" ON "event_data"("website_event_id");+-- CreateIndexCREATE UNIQUE INDEX "team_team_id_key" ON "team"("team_id");+-- CreateIndex+CREATE UNIQUE INDEX "team_access_code_key" ON "team"("access_code");++-- CreateIndex+CREATE INDEX "team_access_code_idx" ON "team"("access_code");+-- CreateIndexCREATE UNIQUE INDEX "team_user_team_user_id_key" ON "team_user"("team_user_id");--- AddForeignKey-ALTER TABLE "website" ADD CONSTRAINT "website_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "team"("team_id") ON DELETE SET NULL ON UPDATE CASCADE;+-- CreateIndex+CREATE INDEX "team_user_team_id_idx" ON "team_user"("team_id");--- AddForeignKey-ALTER TABLE "website" ADD CONSTRAINT "website_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;+-- CreateIndex+CREATE INDEX "team_user_user_id_idx" ON "team_user"("user_id");--- AddForeignKey-ALTER TABLE "team_user" ADD CONSTRAINT "team_user_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "team"("team_id") ON DELETE RESTRICT ON UPDATE CASCADE;+-- CreateIndex+CREATE UNIQUE INDEX "team_website_team_website_id_key" ON "team_website"("team_website_id");++-- CreateIndex+CREATE INDEX "team_website_team_id_idx" ON "team_website"("team_id");--- AddForeignKey-ALTER TABLE "team_user" ADD CONSTRAINT "team_user_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("user_id") ON DELETE RESTRICT ON UPDATE CASCADE;+-- CreateIndex+CREATE INDEX "team_website_website_id_idx" ON "team_website"("website_id");-- AddSystemUserINSERT INTO "user" (user_id, username, role, password) VALUES ('41e2b680-648e-4b09-bcd7-3e2b10c06264' , 'admin', 'admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa');diff --git a/db/postgresql/migrations/02_add_access_code/migration.sql b/db/postgresql/migrations/02_add_access_code/migration.sqldeleted file mode 100644index 9f27d6148..000000000--- a/db/postgresql/migrations/02_add_access_code/migration.sql+++ /dev/null@@ -1,27 +0,0 @@-/*- Warnings:-- - You are about to alter the column `share_id` on the `website` table. The data in that column could be lost. The data in that column will be cast from `VarChar(64)` to `VarChar(50)`.- - A unique constraint covering the columns `[access_code]` on the table `team` will be added. If there are existing duplicate values, this will fail.--*/--- AlterTable-ALTER TABLE "team" ADD COLUMN "access_code" VARCHAR(50);---- AlterTable-ALTER TABLE "website" ALTER COLUMN "share_id" SET DATA TYPE VARCHAR(50);---- CreateIndex-CREATE UNIQUE INDEX "team_access_code_key" ON "team"("access_code");---- CreateIndex-CREATE INDEX "team_user_id_idx" ON "team"("user_id");---- CreateIndex-CREATE INDEX "team_access_code_idx" ON "team"("access_code");---- CreateIndex-CREATE INDEX "team_user_team_id_idx" ON "team_user"("team_id");---- CreateIndex-CREATE INDEX "team_user_user_id_idx" ON "team_user"("user_id");diff --git a/db/postgresql/migrations/03_drop_foreign_keys/migration.sql b/db/postgresql/migrations/03_drop_foreign_keys/migration.sqldeleted file mode 100644index 1e71cedee..000000000--- a/db/postgresql/migrations/03_drop_foreign_keys/migration.sql+++ /dev/null@@ -1,17 +0,0 @@--- DropForeignKey-ALTER TABLE "team_user" DROP CONSTRAINT "team_user_team_id_fkey";---- DropForeignKey-ALTER TABLE "team_user" DROP CONSTRAINT "team_user_user_id_fkey";---- DropForeignKey-ALTER TABLE "website" DROP CONSTRAINT "website_team_id_fkey";---- DropForeignKey-ALTER TABLE "website" DROP CONSTRAINT "website_user_id_fkey";---- CreateIndex-CREATE INDEX "website_team_id_idx" ON "website"("team_id");---- CreateIndex-CREATE INDEX "website_user_id_idx" ON "website"("user_id");diff --git a/db/postgresql/migrations/04_add_team_website/migration.sql b/db/postgresql/migrations/04_add_team_website/migration.sqldeleted file mode 100644index 05ddd53cb..000000000--- a/db/postgresql/migrations/04_add_team_website/migration.sql+++ /dev/null@@ -1,42 +0,0 @@-/*- Warnings:-- - You are about to drop the column `deleted_at` on the `team` table. All the data in the column will be lost.- - You are about to drop the column `deleted_at` on the `team_user` table. All the data in the column will be lost.- - You are about to drop the column `team_id` on the `website` table. All the data in the column will be lost.--*/--- DropIndex-DROP INDEX "website_team_id_idx";---- AlterTable-ALTER TABLE "team" DROP COLUMN "deleted_at";---- AlterTable-ALTER TABLE "team_user" DROP COLUMN "deleted_at";---- AlterTable-ALTER TABLE "website" DROP COLUMN "team_id";---- CreateTable-CREATE TABLE "team_website" (- "team_website_id" UUID NOT NULL,- "team_id" UUID NOT NULL,- "user_id" UUID NOT NULL,- "website_id" UUID NOT NULL,- "created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,-- CONSTRAINT "team_website_pkey" PRIMARY KEY ("team_website_id")-);---- CreateIndex-CREATE UNIQUE INDEX "team_website_team_website_id_key" ON "team_website"("team_website_id");---- CreateIndex-CREATE INDEX "team_website_team_id_idx" ON "team_website"("team_id");---- CreateIndex-CREATE INDEX "team_website_user_id_idx" ON "team_website"("user_id");---- CreateIndex-CREATE INDEX "team_website_website_id_idx" ON "team_website"("website_id");diff --git a/db/postgresql/migrations/05_add_page_title_subdivision_city/migration.sql b/db/postgresql/migrations/05_add_page_title_subdivision_city/migration.sqldeleted file mode 100644index 199d2da79..000000000--- a/db/postgresql/migrations/05_add_page_title_subdivision_city/migration.sql+++ /dev/null@@ -1,7 +0,0 @@--- AlterTable-ALTER TABLE "session" ADD COLUMN "city" VARCHAR(50),-ADD COLUMN "subdivision1" CHAR(3),-ADD COLUMN "subdivision2" VARCHAR(50);---- AlterTable-ALTER TABLE "website_event" ADD COLUMN "page_title" VARCHAR(500);diff --git a/db/postgresql/migrations/06_remove_event_data/migration.sql b/db/postgresql/migrations/06_remove_event_data/migration.sqldeleted file mode 100644index e667026cb..000000000--- a/db/postgresql/migrations/06_remove_event_data/migration.sql+++ /dev/null@@ -1,8 +0,0 @@-/*- Warnings:-- - You are about to drop the column `event_data` on the `website_event` table. All the data in the column will be lost.--*/--- AlterTable-ALTER TABLE "website_event" DROP COLUMN "event_data";diff --git a/db/postgresql/migrations/07_remove_user_id/migration.sql b/db/postgresql/migrations/07_remove_user_id/migration.sqldeleted file mode 100644index ff92f5456..000000000--- a/db/postgresql/migrations/07_remove_user_id/migration.sql+++ /dev/null@@ -1,18 +0,0 @@-/*- Warnings:-- - You are about to drop the column `user_id` on the `team` table. All the data in the column will be lost.- - You are about to drop the column `user_id` on the `team_website` table. All the data in the column will be lost.--*/--- DropIndex-DROP INDEX "team_user_id_idx";---- DropIndex-DROP INDEX "team_website_user_id_idx";---- AlterTable-ALTER TABLE "team" DROP COLUMN "user_id";---- AlterTable-ALTER TABLE "team_website" DROP COLUMN "user_id";\ No newline at end of filediff --git a/db/postgresql/migrations/08_split_url_referrer/migration.sql b/db/postgresql/migrations/08_split_url_referrer/migration.sqldeleted file mode 100644index 7129d87af..000000000--- a/db/postgresql/migrations/08_split_url_referrer/migration.sql+++ /dev/null@@ -1,16 +0,0 @@-/*- Warnings:-- - You are about to drop the column `referrer` on the `website_event` table. All the data in the column will be lost.- - You are about to drop the column `url` on the `website_event` table. All the data in the column will be lost.- - Added the required column `url_path` to the `website_event` table without a default value. This is not possible if the table is not empty.--*/--- AlterTable-ALTER TABLE "website_event" DROP COLUMN "referrer",-DROP COLUMN "url",-ADD COLUMN "referrer_domain" VARCHAR(500),-ADD COLUMN "referrer_path" VARCHAR(500),-ADD COLUMN "referrer_query" VARCHAR(500),-ADD COLUMN "url_path" VARCHAR(500) NOT NULL,-ADD COLUMN "url_query" VARCHAR(500);diff --git a/db/postgresql/migrations/09_event_data/migration.sql b/db/postgresql/migrations/09_event_data/migration.sqldeleted file mode 100644index 1196e1c71..000000000--- a/db/postgresql/migrations/09_event_data/migration.sql+++ /dev/null@@ -1,23 +0,0 @@--- CreateTable-CREATE TABLE "event_data" (- "event_id" UUID NOT NULL,- "website_id" UUID NOT NULL,- "website_event_id" UUID NOT NULL,- "event_key" VARCHAR(500) NOT NULL,- "event_string_value" VARCHAR(500),- "event_numeric_value" DECIMAL(19,4),- "event_date_value" TIMESTAMPTZ(6),- "event_data_type" INTEGER NOT NULL,- "created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,-- CONSTRAINT "event_data_pkey" PRIMARY KEY ("event_id")-);---- CreateIndex-CREATE INDEX "event_data_created_at_idx" ON "event_data"("created_at");---- CreateIndex-CREATE INDEX "event_data_website_id_idx" ON "event_data"("website_id");---- CreateIndex-CREATE INDEX "event_data_website_event_id_idx" ON "event_data"("website_event_id");diff --git a/db/postgresql/migrations/10_add_reset_at/migration.sql b/db/postgresql/migrations/10_add_reset_at/migration.sqldeleted file mode 100644index ba185e1bf..000000000--- a/db/postgresql/migrations/10_add_reset_at/migration.sql+++ /dev/null@@ -1,9 +0,0 @@-/*- Warnings:-- - You are about to drop the column `rev_id` on the `website` table. All the data in the column will be lost.--*/--- AlterTable-ALTER TABLE "website" DROP COLUMN "rev_id",-ADD COLUMN "reset_at" TIMESTAMPTZ(6);