mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
> closes #26403 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [x] Added/updated automated tests - [x] Manual QA for all new/changed functionality
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package tables
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func init() {
|
|
MigrationClient.AddMigration(Up_20220713091130, Down_20220713091130)
|
|
}
|
|
|
|
func Up_20220713091130(tx *sql.Tx) error {
|
|
// Length of VARCHAR set to conform with max key length limitations for the unique constraint
|
|
_, err := tx.Exec(`
|
|
CREATE TABLE operating_systems (
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
version VARCHAR(150) NOT NULL,
|
|
arch VARCHAR(150) NOT NULL,
|
|
kernel_version VARCHAR(150) NOT NULL,
|
|
platform VARCHAR(50) NOT NULL,
|
|
UNIQUE KEY idx_unique_os (name, version, arch, kernel_version, platform)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
`)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "create operating_systems table")
|
|
}
|
|
|
|
_, err = tx.Exec(`
|
|
CREATE TABLE host_operating_system (
|
|
host_id INT UNSIGNED NOT NULL PRIMARY KEY,
|
|
os_id INT UNSIGNED NOT NULL,
|
|
FOREIGN KEY fk_operating_systems_id (os_id) REFERENCES operating_systems(id) ON DELETE CASCADE,
|
|
INDEX idx_host_operating_system_id (os_id)
|
|
)`)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "create host_operating_systems table")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Down_20220713091130(tx *sql.Tx) error {
|
|
return nil
|
|
}
|