Skip to content

The only tool you need to know what is happening and how to fix it.

bug: migrations with building new tables

ddux0d1959914618
diff --git a/backend/app/migrations/ch/0009_rename_segments_to_segments_old.up.sql b/backend/app/migrations/ch/0009_rename_segments_to_segments_old.up.sql
new file mode 100644
index 00000000..7ff0b7f6
--- /dev/null
+++ b/backend/app/migrations/ch/0009_rename_segments_to_segments_old.up.sql
@@ -0,0 +1 @@
+RENAME TABLE segments TO segments_old;
diff --git a/backend/app/migrations/ch/0009_rename_transaction_to_trace_segments.up.sql b/backend/app/migrations/ch/0009_rename_transaction_to_trace_segments.up.sql
deleted file mode 100644
index 73a8b803..00000000
--- a/backend/app/migrations/ch/0009_rename_transaction_to_trace_segments.up.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-ALTER TABLE segments RENAME COLUMN transaction_id TO trace_id;
-ALTER TABLE segments DROP INDEX idx_transaction_id;
-ALTER TABLE segments ADD INDEX idx_trace_id trace_id TYPE bloom_filter(0.001) GRANULARITY 1;
diff --git a/backend/app/migrations/ch/0010_create_segments_with_trace_id.up.sql b/backend/app/migrations/ch/0010_create_segments_with_trace_id.up.sql
new file mode 100644
index 00000000..c3d5dd07
--- /dev/null
+++ b/backend/app/migrations/ch/0010_create_segments_with_trace_id.up.sql
@@ -0,0 +1,15 @@
+CREATE TABLE IF NOT EXISTS segments
+(
+ `id` UUID,
+ `trace_id` UUID,
+ `project_id` UUID,
+ `name` LowCardinality(String),
+ `start_time` DateTime64(6),
+ `duration` Int64,
+ `recorded_at` DateTime,
+ INDEX idx_trace_id trace_id TYPE bloom_filter(0.001) GRANULARITY 1
+)
+ENGINE = MergeTree
+PARTITION BY toYYYYMMDD(recorded_at)
+ORDER BY (project_id, trace_id, start_time)
+SETTINGS index_granularity = 8192;
diff --git a/backend/app/migrations/ch/0010_rename_transaction_to_trace_exceptions.up.sql b/backend/app/migrations/ch/0010_rename_transaction_to_trace_exceptions.up.sql
deleted file mode 100644
index c29b66c6..00000000
--- a/backend/app/migrations/ch/0010_rename_transaction_to_trace_exceptions.up.sql
+++ /dev/null
@@ -1,4 +0,0 @@
-ALTER TABLE exception_stack_traces RENAME COLUMN transaction_id TO trace_id;
-ALTER TABLE exception_stack_traces RENAME COLUMN transaction_type TO trace_type;
-ALTER TABLE exception_stack_traces DROP INDEX idx_transaction_id;
-ALTER TABLE exception_stack_traces ADD INDEX idx_trace_id trace_id TYPE bloom_filter(0.01) GRANULARITY 4;
diff --git a/backend/app/migrations/ch/0011_reinsert_segments_from_old.up.sql b/backend/app/migrations/ch/0011_reinsert_segments_from_old.up.sql
new file mode 100644
index 00000000..8bb61676
--- /dev/null
+++ b/backend/app/migrations/ch/0011_reinsert_segments_from_old.up.sql
@@ -0,0 +1,3 @@
+INSERT INTO segments (id, trace_id, project_id, name, start_time, duration, recorded_at)
+SELECT id, transaction_id, project_id, name, start_time, duration, recorded_at
+FROM segments_old;
diff --git a/backend/app/migrations/ch/0012_drop_segments_old.up.sql b/backend/app/migrations/ch/0012_drop_segments_old.up.sql
new file mode 100644
index 00000000..f044b58f
--- /dev/null
+++ b/backend/app/migrations/ch/0012_drop_segments_old.up.sql
@@ -0,0 +1 @@
+DROP TABLE segments_old;
diff --git a/backend/app/migrations/ch/0013_rename_exceptions_to_exceptions_old.up.sql b/backend/app/migrations/ch/0013_rename_exceptions_to_exceptions_old.up.sql
new file mode 100644
index 00000000..705bb7ad
--- /dev/null
+++ b/backend/app/migrations/ch/0013_rename_exceptions_to_exceptions_old.up.sql
@@ -0,0 +1 @@
+RENAME TABLE exception_stack_traces TO exception_stack_traces_old;
diff --git a/backend/app/migrations/ch/0014_create_exceptions_with_trace_id.up.sql b/backend/app/migrations/ch/0014_create_exceptions_with_trace_id.up.sql
new file mode 100644
index 00000000..c4a5a38b
--- /dev/null
+++ b/backend/app/migrations/ch/0014_create_exceptions_with_trace_id.up.sql
@@ -0,0 +1,23 @@
+CREATE TABLE IF NOT EXISTS exception_stack_traces
+(
+ `id` UUID,
+ `project_id` UUID,
+ `trace_id` Nullable(UUID),
+ `trace_type` LowCardinality(String) DEFAULT 'endpoint',
+ `exception_hash` String,
+ `stack_trace` String,
+ `recorded_at` DateTime,
+ `scope` String DEFAULT '{}',
+ `app_version` LowCardinality(String) DEFAULT '',
+ `server_name` LowCardinality(String) DEFAULT '',
+ `is_message` UInt8 DEFAULT 0,
+ INDEX idx_exception_hash exception_hash TYPE bloom_filter(0.01) GRANULARITY 4,
+ INDEX idx_trace_id trace_id TYPE bloom_filter(0.01) GRANULARITY 4,
+ INDEX idx_is_message is_message TYPE set(2) GRANULARITY 1,
+ INDEX idx_id id TYPE bloom_filter(0.001) GRANULARITY 1,
+ INDEX idx_stack_trace stack_trace TYPE tokenbf_v1(10240, 3, 0) GRANULARITY 4
+)
+ENGINE = MergeTree
+PARTITION BY toYYYYMMDD(recorded_at)
+ORDER BY (project_id, recorded_at, exception_hash)
+SETTINGS index_granularity = 8192;
diff --git a/backend/app/migrations/ch/0015_reinsert_exceptions_from_old.up.sql b/backend/app/migrations/ch/0015_reinsert_exceptions_from_old.up.sql
new file mode 100644
index 00000000..43d179fc
--- /dev/null
+++ b/backend/app/migrations/ch/0015_reinsert_exceptions_from_old.up.sql
@@ -0,0 +1,3 @@
+INSERT INTO exception_stack_traces (id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, scope, app_version, server_name, is_message)
+SELECT id, project_id, transaction_id, transaction_type, exception_hash, stack_trace, recorded_at, scope, app_version, server_name, is_message
+FROM exception_stack_traces_old;
diff --git a/backend/app/migrations/ch/0016_drop_exceptions_old.up.sql b/backend/app/migrations/ch/0016_drop_exceptions_old.up.sql
new file mode 100644
index 00000000..f92198c4
--- /dev/null
+++ b/backend/app/migrations/ch/0016_drop_exceptions_old.up.sql
@@ -0,0 +1 @@
+DROP TABLE exception_stack_traces_old;
diff --git a/backend/app/migrations/ch/0011_rename_transactions_to_traces.up.sql b/backend/app/migrations/ch/0017_rename_transactions_to_traces.up.sql
similarity index 100%
rename from backend/app/migrations/ch/0011_rename_transactions_to_traces.up.sql
rename to backend/app/migrations/ch/0017_rename_transactions_to_traces.up.sql
diff --git a/backend/app/migrations/ch/0012_rename_segments_to_spans.up.sql b/backend/app/migrations/ch/0018_rename_segments_to_spans.up.sql
similarity index 100%
rename from backend/app/migrations/ch/0012_rename_segments_to_spans.up.sql
rename to backend/app/migrations/ch/0018_rename_segments_to_spans.up.sql
diff --git a/backend/app/migrations/ch/0013_rename_scope_to_attributes_endpoints.up.sql b/backend/app/migrations/ch/0019_rename_scope_to_attributes_endpoints.up.sql
similarity index 100%
rename from backend/app/migrations/ch/0013_rename_scope_to_attributes_endpoints.up.sql
rename to backend/app/migrations/ch/0019_rename_scope_to_attributes_endpoints.up.sql
diff --git a/backend/app/migrations/ch/0014_rename_scope_to_attributes_tasks.up.sql b/backend/app/migrations/ch/0020_rename_scope_to_attributes_tasks.up.sql
similarity index 100%
rename from backend/app/migrations/ch/0014_rename_scope_to_attributes_tasks.up.sql
rename to backend/app/migrations/ch/0020_rename_scope_to_attributes_tasks.up.sql
diff --git a/backend/app/migrations/ch/0015_rename_scope_to_attributes_exception_stack_traces.up.sql b/backend/app/migrations/ch/0021_rename_scope_to_attributes_exception_stack_traces.up.sql
similarity index 100%
rename from backend/app/migrations/ch/0015_rename_scope_to_attributes_exception_stack_traces.up.sql
rename to backend/app/migrations/ch/0021_rename_scope_to_attributes_exception_stack_traces.up.sql
diff --git a/backend/app/migrations/ch/0016_rename_scope_to_attributes_transactions.up.sql b/backend/app/migrations/ch/0022_rename_scope_to_attributes_transactions.up.sql
similarity index 100%
rename from backend/app/migrations/ch/0016_rename_scope_to_attributes_transactions.up.sql
rename to backend/app/migrations/ch/0022_rename_scope_to_attributes_transactions.up.sql