Skip to content

Commit 1337c50

Browse files
committed
when creating timeseries_data, never create unnecessary indexes
save space and time during migration process
1 parent f36fd16 commit 1337c50

File tree

3 files changed

+3
-44
lines changed

3 files changed

+3
-44
lines changed

acarshub-backend/drizzle/0001_add_timeseries_stats.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,5 @@ CREATE TABLE IF NOT EXISTS `timeseries_stats` (
1616
`created_at` integer NOT NULL
1717
);
1818

19-
-- Index for efficient time-range queries
20-
CREATE INDEX `idx_timeseries_timestamp_resolution` ON `timeseries_stats` (`timestamp`, `resolution`);
21-
22-
-- Index for filtering by resolution
23-
CREATE INDEX `idx_timeseries_resolution` ON `timeseries_stats` (`resolution`);
24-
2519
-- Add constraint check for resolution enum (SQLite doesn't have native ENUM)
2620
-- Valid values: '1min', '5min', '1hour', '6hour'

acarshub-backend/src/db/migrate.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -880,16 +880,6 @@ function migration09_addTimeseriesStats(db: Database.Database): void {
880880
created_at INTEGER NOT NULL
881881
)
882882
`);
883-
884-
db.exec(`
885-
CREATE INDEX idx_timeseries_timestamp_resolution
886-
ON timeseries_stats (timestamp, resolution)
887-
`);
888-
889-
db.exec(`
890-
CREATE INDEX idx_timeseries_resolution
891-
ON timeseries_stats (resolution)
892-
`);
893883
});
894884

895885
migrate();
@@ -1024,26 +1014,7 @@ function migration11_deduplicateTimeseriesAndAddRegistry(
10241014
}
10251015

10261016
// -------------------------------------------------------------------------
1027-
// Step 2: Replace non-unique index with unique index
1028-
// -------------------------------------------------------------------------
1029-
// Drop the old non-unique index (created by migration 9). SQLite does not
1030-
// support ALTER INDEX, so we drop and recreate.
1031-
db.exec(
1032-
"DROP INDEX IF EXISTS idx_timeseries_timestamp_resolution",
1033-
);
1034-
1035-
// The table is now duplicate-free, so this will succeed.
1036-
db.exec(`
1037-
CREATE UNIQUE INDEX idx_timeseries_timestamp_resolution
1038-
ON timeseries_stats (timestamp, resolution)
1039-
`);
1040-
1041-
logger.info(
1042-
"Replaced non-unique index with UNIQUE index on timeseries_stats(timestamp, resolution)",
1043-
);
1044-
1045-
// -------------------------------------------------------------------------
1046-
// Step 3: Create rrd_import_registry table
1017+
// Step 2: Create rrd_import_registry table
10471018
// -------------------------------------------------------------------------
10481019
db.exec(`
10491020
CREATE TABLE IF NOT EXISTS rrd_import_registry (
@@ -1142,8 +1113,8 @@ function migration12_dropResolutionPromoteTimestampPk(
11421113

11431114
// Free space for adsb.im users. Also anyone else.
11441115

1145-
db.exec(`DROP INDEX idx_timeseries_resolution;`);
1146-
db.exec(`DROP INDEX idx_timeseries_timestamp_resolution;`);
1116+
db.exec(`DROP INDEX IF EXISTS idx_timeseries_resolution;`);
1117+
db.exec(`DROP INDEX IF EXISTS idx_timeseries_timestamp_resolution;`);
11471118

11481119
// -----------------------------------------------------------------------
11491120
// Step 2: Create new table — timestamp is INTEGER PRIMARY KEY (rowid alias)

dev-docs/TIMESERIES_STRATEGY.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,6 @@ CREATE TABLE timeseries_stats (
267267
error_count INTEGER DEFAULT 0 NOT NULL,
268268
created_at INTEGER NOT NULL -- Insertion timestamp
269269
);
270-
271-
CREATE INDEX idx_timeseries_timestamp_resolution
272-
ON timeseries_stats (timestamp, resolution);
273-
274-
CREATE INDEX idx_timeseries_resolution
275-
ON timeseries_stats (resolution);
276270
```
277271

278272
## Configuration

0 commit comments

Comments
 (0)