Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 120 additions & 193 deletions static/migrations/0001_create_monoscope_tables.sql

Large diffs are not rendered by default.

41 changes: 33 additions & 8 deletions static/migrations/0002_logs_traces_metrics.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
CREATE SCHEMA IF NOT EXISTS telemetry;

-- Define the ENUM type for severity_text
CREATE TYPE telemetry.severity_level AS ENUM ('DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL');
-- Define the ENUM type for severity_text (safe for re-runs)
DO $$ BEGIN
CREATE TYPE telemetry.severity_level AS ENUM ('DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL');
EXCEPTION WHEN duplicate_object THEN null;
END $$;

-- =================================================================
-- TRACES
-- =================================================================
CREATE TYPE telemetry.span_status AS ENUM ('OK', 'ERROR', 'UNSET');
DO $$ BEGIN
CREATE TYPE telemetry.span_status AS ENUM ('OK', 'ERROR', 'UNSET');
EXCEPTION WHEN duplicate_object THEN null;
END $$;

-- Define the ENUM type for span kind
CREATE TYPE telemetry.span_kind AS ENUM ('INTERNAL', 'SERVER', 'CLIENT', 'PRODUCER', 'CONSUMER');
-- Define the ENUM type for span kind (safe for re-runs)
DO $$ BEGIN
CREATE TYPE telemetry.span_kind AS ENUM ('INTERNAL', 'SERVER', 'CLIENT', 'PRODUCER', 'CONSUMER');
EXCEPTION WHEN duplicate_object THEN null;
END $$;


CREATE TABLE IF NOT EXISTS telemetry.metrics (
Expand Down Expand Up @@ -56,7 +66,10 @@ SELECT manage_updated_at('telemetry.metrics_meta');
-- =================================================================
-- Query history and saved queries
-- =================================================================
CREATE TYPE projects.query_library_kind AS ENUM ('history', 'saved');
DO $$ BEGIN
CREATE TYPE projects.query_library_kind AS ENUM ('history', 'saved');
EXCEPTION WHEN duplicate_object THEN null;
END $$;
CREATE TABLE IF NOT EXISTS projects.query_library (
id UUID NOT NULL DEFAULT gen_random_uuid(),
project_id UUID NOT NULL REFERENCES projects.projects (id) ON DELETE CASCADE,
Expand Down Expand Up @@ -90,9 +103,14 @@ CREATE TABLE IF NOT EXISTS projects.dashboards (
homepage_since TIMESTAMP WITH TIME ZONE,
tags TEXT[] NOT NULL DEFAULT '{}',
title TEXT NOT NULL DEFAULT 'Untitled',
-- Consolidated from migration 0017, 0020
teams UUID[] DEFAULT '{}',
file_path TEXT,
file_sha TEXT,
PRIMARY KEY (id)
);
SELECT manage_updated_at('projects.dashboards');
CREATE INDEX IF NOT EXISTS idx_dashboards_file_path ON projects.dashboards(project_id, file_path) WHERE file_path IS NOT NULL;



Expand Down Expand Up @@ -186,7 +204,7 @@ CREATE TABLE IF NOT EXISTS otel_logs_and_spans (
date TIMESTAMPTZ NOT NULL DEFAULT current_timestamp
);
SELECT create_hypertable('otel_logs_and_spans', by_range('timestamp', INTERVAL '1 hours'), migrate_data => true, if_not_exists => true);
SELECT add_retention_policy('otel_logs_and_spans',INTERVAL '14 days',true);
SELECT add_retention_policy('otel_logs_and_spans',INTERVAL '30 days',true);

CREATE INDEX IF NOT EXISTS idx_logs_and_spans_trace_id ON otel_logs_and_spans (project_id, context___trace_id);
CREATE INDEX IF NOT EXISTS idx_logs_and_spans_span_id ON otel_logs_and_spans (project_id, context___span_id);
Expand All @@ -195,4 +213,11 @@ CREATE INDEX IF NOT EXISTS idx_logs_and_spans_service_name ON otel_logs_and_span
CREATE INDEX IF NOT EXISTS idx_logs_and_spans_name ON otel_logs_and_spans (project_id, name);

ALTER TABLE otel_logs_and_spans
ADD COLUMN IF NOT EXISTS errors JSONB DEFAULT NULL;
ADD COLUMN IF NOT EXISTS errors JSONB DEFAULT NULL;

-- Columns consolidated from later migrations (0013, 0015)
ALTER TABLE otel_logs_and_spans
ADD COLUMN IF NOT EXISTS log_pattern TEXT DEFAULT NULL;

ALTER TABLE otel_logs_and_spans
ADD COLUMN IF NOT EXISTS summary_pattern TEXT DEFAULT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ CREATE TABLE apis.issues

-- LLM enhancement tracking
llm_enhanced_at TIMESTAMP WITH TIME ZONE,
llm_enhancement_version INTEGER DEFAULT 1,
-- Constraint: Only one unacknowledged/unarchived API change issue per endpoint
CONSTRAINT unique_open_api_change_per_endpoint UNIQUE (project_id, issue_type, endpoint_hash)
DEFERRABLE INITIALLY DEFERRED
llm_enhancement_version INTEGER DEFAULT 1

-- NOTE: We use a partial unique index (unique_open_api_change_issue_per_endpoint below)
-- instead of a table-level constraint. The partial index correctly enforces:
-- "only one OPEN api_change issue per endpoint" while allowing multiple closed issues.
);

-- Add trigger for updated_at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- Teams table for organizing project members and notification routing
BEGIN;

CREATE TABLE IF NOT EXISTS projects.teams (
Expand All @@ -8,7 +9,7 @@ CREATE TABLE IF NOT EXISTS projects.teams (
description TEXT,
members UUID[] DEFAULT '{}',
notify_emails TEXT[] DEFAULT '{}',
slack_channels TEXT[] DEFAULT '{}',
slack_channels TEXT[] DEFAULT '{}',
discord_channels TEXT[] DEFAULT '{}',
phone_numbers TEXT[] DEFAULT '{}',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
Expand All @@ -19,10 +20,6 @@ CREATE TABLE IF NOT EXISTS projects.teams (
);
SELECT manage_updated_at('projects.teams');

ALTER TABLE monitors.query_monitors ADD COLUMN IF NOT EXISTS teams UUID[] DEFAULT '{}';

ALTER TABLE projects.dashboards ADD COLUMN IF NOT EXISTS teams UUID[] DEFAULT '{}';

CREATE INDEX IF NOT EXISTS idx_teams_project_id ON projects.teams(project_id) WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_teams_handle ON projects.teams(project_id, handle) WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_teams_members_gin ON projects.teams USING GIN(members);
Expand Down
20 changes: 0 additions & 20 deletions static/migrations/0006_add_llm_enhancement_tracking.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,3 @@ CREATE TABLE IF NOT EXISTS projects.github_sync (
CREATE INDEX IF NOT EXISTS idx_github_sync_project_id ON projects.github_sync(project_id);
CREATE INDEX IF NOT EXISTS idx_github_sync_owner_repo ON projects.github_sync(owner, repo);
CREATE INDEX IF NOT EXISTS idx_github_sync_installation ON projects.github_sync(installation_id) WHERE installation_id IS NOT NULL;

-- Add file path and content hash columns to dashboards
-- file_path: canonical path like "folder/dashboard-title.yaml"
-- file_sha: SHA256 hash of the YAML content for change detection
ALTER TABLE projects.dashboards
ADD COLUMN IF NOT EXISTS file_path TEXT,
ADD COLUMN IF NOT EXISTS file_sha TEXT;

CREATE INDEX IF NOT EXISTS idx_dashboards_file_path ON projects.dashboards(project_id, file_path) WHERE file_path IS NOT NULL;
80 changes: 0 additions & 80 deletions static/migrations/0008_use_non_defferable_contraint_on_issues.sql

This file was deleted.

9 changes: 0 additions & 9 deletions static/migrations/0009_make_retention_policy_30.sql

This file was deleted.

48 changes: 0 additions & 48 deletions static/migrations/0010_requbild_ers_view.sql

This file was deleted.

45 changes: 0 additions & 45 deletions static/migrations/0011_host_request_stats.sql

This file was deleted.

6 changes: 0 additions & 6 deletions static/migrations/0012_drop_materialized_views.sql

This file was deleted.

6 changes: 0 additions & 6 deletions static/migrations/0013_log_patterns.sql

This file was deleted.

4 changes: 0 additions & 4 deletions static/migrations/0014_alerts_config.sql

This file was deleted.

4 changes: 0 additions & 4 deletions static/migrations/0015_summary_pattern.sql

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions static/migrations/0016_reports_start_and_end_time.sql

This file was deleted.

Loading
Loading