This document describes the migration of the timestamp_begin field from time.Time to int64 in the player_money_data table.
The timestamp_begin field in the PlayerMoneyData struct has been migrated from time.Time to int64 to store Unix nanoseconds for better performance and consistency.
- Before:
timestamp_begin TIMESTAMP - After:
timestamp_begin BIGINT
- Updated
PlayerMoneyDatastruct to useint64forTimestampBegin - Updated
CreatePlayerMoneyDataRequeststruct to useint64forTimestampBegin - Updated service methods to handle
int64timestamps - Updated
enhanced_replay.goto convert timestamps to int64 nanoseconds
The migration script (pkg/database/migration.go) performs the following steps:
- Adds a temporary
timestamp_begin_int64column - Converts existing timestamp data to Unix nanoseconds
- Drops the unique index on the old column
- Drops the old
timestamp_begincolumn - Renames the new column to
timestamp_begin - Sets NOT NULL constraint on the new column
- Recreates the unique index
Existing timestamps are converted using PostgreSQL's EXTRACT(EPOCH FROM timestamp_begin) * 1000000000 to get Unix nanoseconds.
Run the test script to verify the migration:
go run test_migration_local.goThis will:
- Check the current column type
- Run the migration (with fallback to manual migration if needed)
- Verify the column type changed to bigint
- Create a test record with int64 timestamp
- Verify the record can be retrieved correctly
The migration includes automatic fallback mechanisms for Heroku's PostgreSQL:
- First tries the standard SQL migration
- Falls back to manual row-by-row migration if the standard approach fails
- Handles different PostgreSQL timestamp types (timestamp vs timestamptz)
If rollback is needed, you would need to:
- Convert int64 values back to timestamps
- Recreate the timestamp column
- Update the application code to use time.Time again
The API now expects and returns timestamp_begin as an integer (Unix nanoseconds) instead of an ISO timestamp string.
{
"timestamp_begin": "2023-12-01T10:30:00Z",
"timecode": 12345
}{
"timestamp_begin": 1701429000000000000,
"timecode": 12345
}The migration includes utility functions in pkg/database/migration.go:
ConvertTimeToInt64(t time.Time) int64- Convert time.Time to int64 nanosecondsConvertInt64ToTime(ns int64) time.Time- Convert int64 nanoseconds to time.Time