storagenode/satellitesdb: added FK constraint to satelliteID
Change-Id: If5adf2b92627fcf80850670ba672b346320ddd87
This commit is contained in:
parent
45ccf59067
commit
f5ac678b0a
@ -1410,6 +1410,42 @@ func (db *DB) Migration(ctx context.Context) *migrate.Migration {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}),
|
||||
},
|
||||
{
|
||||
DB: db.satellitesDB,
|
||||
Description: "Make satellite_id foreign key in satellite_exit_progress table",
|
||||
Version: 41,
|
||||
Action: migrate.Func(func(ctx context.Context, _ *zap.Logger, rdb tagsql.DB, rtx tagsql.Tx) (err error) {
|
||||
_, err = rtx.Exec(ctx, `
|
||||
CREATE TABLE satellite_exit_progress_new (
|
||||
satellite_id BLOB NOT NULL,
|
||||
initiated_at TIMESTAMP,
|
||||
finished_at TIMESTAMP,
|
||||
starting_disk_usage INTEGER NOT NULL,
|
||||
bytes_deleted INTEGER NOT NULL,
|
||||
completion_receipt BLOB,
|
||||
FOREIGN KEY (satellite_id) REFERENCES satellites (node_id)
|
||||
);
|
||||
|
||||
INSERT INTO satellite_exit_progress_new SELECT
|
||||
satellite_id,
|
||||
initiated_at,
|
||||
finished_at,
|
||||
starting_disk_usage,
|
||||
bytes_deleted,
|
||||
completion_receipt
|
||||
FROM satellite_exit_progress;
|
||||
|
||||
DROP TABLE satellite_exit_progress;
|
||||
|
||||
ALTER TABLE satellite_exit_progress_new RENAME TO satellite_exit_progress;
|
||||
`)
|
||||
if err != nil {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}),
|
||||
},
|
||||
|
@ -577,8 +577,7 @@ func Schema() map[string]*dbschema.Schema {
|
||||
"satellites": &dbschema.Schema{
|
||||
Tables: []*dbschema.Table{
|
||||
&dbschema.Table{
|
||||
Name: "satellite_exit_progress",
|
||||
PrimaryKey: []string{"satellite_id"},
|
||||
Name: "satellite_exit_progress",
|
||||
Columns: []*dbschema.Column{
|
||||
&dbschema.Column{
|
||||
Name: "bytes_deleted",
|
||||
@ -604,6 +603,7 @@ func Schema() map[string]*dbschema.Schema {
|
||||
Name: "satellite_id",
|
||||
Type: "BLOB",
|
||||
IsNullable: false,
|
||||
Reference: &dbschema.Reference{Table: "satellites", Column: "node_id", OnDelete: "", OnUpdate: ""},
|
||||
},
|
||||
&dbschema.Column{
|
||||
Name: "starting_disk_usage",
|
||||
|
@ -55,6 +55,7 @@ var States = MultiDBStates{
|
||||
&v38,
|
||||
&v39,
|
||||
&v40,
|
||||
&v41,
|
||||
},
|
||||
}
|
||||
|
||||
|
47
storagenode/storagenodedb/testdata/v41.go
vendored
Normal file
47
storagenode/storagenodedb/testdata/v41.go
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2020 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"storj.io/storj/storagenode/storagenodedb"
|
||||
)
|
||||
|
||||
var v41 = MultiDBState{
|
||||
Version: 41,
|
||||
DBStates: DBStates{
|
||||
storagenodedb.UsedSerialsDBName: v40.DBStates[storagenodedb.UsedSerialsDBName],
|
||||
storagenodedb.StorageUsageDBName: v40.DBStates[storagenodedb.StorageUsageDBName],
|
||||
storagenodedb.ReputationDBName: v40.DBStates[storagenodedb.ReputationDBName],
|
||||
storagenodedb.PieceSpaceUsedDBName: v40.DBStates[storagenodedb.PieceSpaceUsedDBName],
|
||||
storagenodedb.PieceInfoDBName: v40.DBStates[storagenodedb.PieceInfoDBName],
|
||||
storagenodedb.PieceExpirationDBName: v40.DBStates[storagenodedb.PieceExpirationDBName],
|
||||
storagenodedb.OrdersDBName: v40.DBStates[storagenodedb.OrdersDBName],
|
||||
storagenodedb.BandwidthDBName: v40.DBStates[storagenodedb.BandwidthDBName],
|
||||
storagenodedb.SatellitesDBName: &DBState{
|
||||
SQL: `
|
||||
CREATE TABLE satellites (
|
||||
node_id BLOB NOT NULL,
|
||||
added_at TIMESTAMP NOT NULL,
|
||||
status INTEGER NOT NULL,
|
||||
PRIMARY KEY (node_id)
|
||||
);
|
||||
CREATE TABLE satellite_exit_progress (
|
||||
satellite_id BLOB NOT NULL,
|
||||
initiated_at TIMESTAMP,
|
||||
finished_at TIMESTAMP,
|
||||
starting_disk_usage INTEGER NOT NULL,
|
||||
bytes_deleted INTEGER NOT NULL,
|
||||
completion_receipt BLOB,
|
||||
FOREIGN KEY (satellite_id) REFERENCES satellites (node_id)
|
||||
);
|
||||
INSERT INTO satellites VALUES(X'0ed28abb2813e184a1e98b0f6605c4911ea468c7e8433eb583e0fca7ceac3000','2019-09-10 20:00:00+00:00', 0);
|
||||
INSERT INTO satellite_exit_progress VALUES(X'0ed28abb2813e184a1e98b0f6605c4911ea468c7e8433eb583e0fca7ceac3000','2019-09-10 20:00:00+00:00', null, 100, 0, null);
|
||||
`,
|
||||
},
|
||||
storagenodedb.DeprecatedInfoDBName: v40.DBStates[storagenodedb.DeprecatedInfoDBName],
|
||||
storagenodedb.NotificationsDBName: v40.DBStates[storagenodedb.NotificationsDBName],
|
||||
storagenodedb.HeldAmountDBName: v40.DBStates[storagenodedb.HeldAmountDBName],
|
||||
storagenodedb.PricingDBName: v40.DBStates[storagenodedb.PricingDBName],
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user