mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
Added gigs_total_disk_space to host_disks. (#15753)
Added gigs_total_disk_space to host_disks. This is just the migration that is needed for the rest of the changes in #15058
This commit is contained in:
parent
367459fe02
commit
72621e31ce
@ -0,0 +1,26 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MigrationClient.AddMigration(Up_20231219143041, Down_20231219143041)
|
||||
}
|
||||
|
||||
func Up_20231219143041(tx *sql.Tx) error {
|
||||
stmt := `
|
||||
ALTER TABLE host_disks
|
||||
ADD COLUMN gigs_total_disk_space decimal(10,2) NOT NULL DEFAULT '0.00';
|
||||
`
|
||||
if _, err := tx.Exec(stmt); err != nil {
|
||||
return fmt.Errorf("add gigs_total_disk_space to host_disks: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Down_20231219143041(tx *sql.Tx) error {
|
||||
return nil
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUp_20231219143041(t *testing.T) {
|
||||
db := applyUpToPrev(t)
|
||||
|
||||
insertStmt := `INSERT INTO host_disks (host_id) VALUES (1)`
|
||||
_, err := db.Exec(insertStmt)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Apply current migration.
|
||||
applyNext(t, db)
|
||||
|
||||
type diskSpace struct {
|
||||
HostID uint `db:"host_id"`
|
||||
GigsTotalDiskSpace float64 `db:"gigs_total_disk_space"`
|
||||
}
|
||||
|
||||
var ds diskSpace
|
||||
err = db.Get(&ds, `SELECT host_id, gigs_total_disk_space from host_disks where host_id = 1`)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, float64(0), ds.GigsTotalDiskSpace)
|
||||
|
||||
_, err = db.Exec(`INSERT INTO host_disks (host_id, gigs_total_disk_space) VALUES (2, 1.5)`)
|
||||
require.NoError(t, err)
|
||||
err = db.Get(&ds, `SELECT host_id, gigs_total_disk_space from host_disks where host_id = 2`)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1.5, ds.GigsTotalDiskSpace)
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user