aboutsummaryrefslogtreecommitdiffstats
path: root/internal/migrations/20250625005811_cpu.go
blob: 7f317ac0cb2010c87e92c8c0a282ab49bb4f8862 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package migrations

import (
	"context"
	"database/sql"

	"github.com/pressly/goose/v3"
)

func init() {
	goose.AddMigrationContext(upCpu, downCpu)
}

func upCpu(ctx context.Context, tx *sql.Tx) error {
	_, err := tx.Exec(`CREATE TABLE IF NOT EXISTS cpus (
											id INTEGER PRIMARY KEY AUTO_INCREMENT,
											name VARCHAR(255) NOT NULL,
											freq INTEGER NOT NULL,
											temp INTEGER NOT NULL
										)`)
	if err != nil {
		return err
	}
	return nil
}

func downCpu(ctx context.Context, tx *sql.Tx) error {
	// This code is executed when the migration is rolled back.
	_, err := tx.Exec(`DROP TABLE IF EXISTS cpus`)
	if err != nil {
		return err
	}
	return nil
}