mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
This PR separates the table migrations from the data population migrations. Table migrations run before data migrations. Now, we have the ability to create the database tables without populating them with data. This can be useful for running "unit" tests against a MySQL store that doesn't have any pre-populated data. When performing real migrations, or for more "integration" style testing, the data migrations can also be executed. Note there are some special cases that must be observed with these migrations, and the README is updated to reflect those.
30 lines
869 B
Go
30 lines
869 B
Go
package tables
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
func init() {
|
|
MigrationClient.AddMigration(Up_20161118212549, Down_20161118212549)
|
|
}
|
|
|
|
func Up_20161118212549(tx *sql.Tx) error {
|
|
_, err := tx.Exec(
|
|
"CREATE TABLE `label_query_executions` (" +
|
|
"`id` int(10) unsigned NOT NULL AUTO_INCREMENT," +
|
|
"`created_at` timestamp DEFAULT CURRENT_TIMESTAMP," +
|
|
"`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
|
|
"`matches` tinyint(1) NOT NULL DEFAULT FALSE," +
|
|
"`label_id` int(10) unsigned DEFAULT NULL," +
|
|
"`host_id` int(10) unsigned DEFAULT NULL," +
|
|
"PRIMARY KEY (`id`)," +
|
|
"UNIQUE KEY `idx_lqe_label_host` (`label_id`,`host_id`)" +
|
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
|
)
|
|
return err
|
|
}
|
|
|
|
func Down_20161118212549(tx *sql.Tx) error {
|
|
_, err := tx.Exec("DROP TABLE IF EXISTS `label_query_executions`;")
|
|
return err
|
|
}
|