-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change primary key from 'created_at' to 'id'
We can have multiple events generated at a given time, therefore the value of 'created_at' field will be same for each event. This violates the unique constraint on "events_pkey", when these events are add to the events table. The migration changes the primary key on events table from 'created_at' to `id`, which will always be unique for each event generated at any point in time. Signed-off-by: Gaurav Gahlot <[email protected]>
- Loading branch information
1 parent
617d56a
commit f3a4074
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package migration | ||
|
||
import migrate "github.com/rubenv/sql-migrate" | ||
|
||
// Get2020121691335 updates the primary key on events table. | ||
// | ||
// Fixes: https://github.com/tinkerbell/tink/issues/379 | ||
// | ||
// We can have multiple events generated at a given time, therefore the value of | ||
// 'created_at' field will be same for each event. This violates the unique constraint | ||
// on "events_pkey", when these events are add to the events table. | ||
// | ||
// The migration changes the primary key on events table from 'created_at' to `id`, | ||
// which will always be unique for each event generated at any point in time. | ||
func Get2020121691335() *migrate.Migration { | ||
return &migrate.Migration{ | ||
Id: "2020121691335-update-events-primary-key", | ||
Up: []string{` | ||
ALTER TABLE events DROP CONSTRAINT events_pkey; | ||
ALTER TABLE events ADD PRIMARY KEY (id); | ||
CREATE INDEX IF NOT EXISTS idx_events_created_at ON events (created_at); | ||
`}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters