mirror of
https://github.com/empayre/fleet.git
synced 2024-11-08 09:43:51 +00:00
35806f1442
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
882 B
Go
30 lines
882 B
Go
package tables
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
func init() {
|
|
MigrationClient.AddMigration(Up_20161118212515, Down_20161118212515)
|
|
}
|
|
|
|
func Up_20161118212515(tx *sql.Tx) error {
|
|
sqlStatement := "CREATE TABLE `distributed_query_executions` (" +
|
|
"`id` int(10) unsigned NOT NULL AUTO_INCREMENT," +
|
|
"`host_id` int(10) unsigned DEFAULT NULL," +
|
|
"`distributed_query_campaign_id` int(10) unsigned DEFAULT NULL," +
|
|
"`status` int(11) DEFAULT NULL," +
|
|
"`error` varchar(1024) DEFAULT NULL," +
|
|
"`execution_duration` bigint(20) DEFAULT NULL," +
|
|
"UNIQUE KEY `idx_dqe_unique_host_dqc_id` (`host_id`, `distributed_query_campaign_id`)," +
|
|
"PRIMARY KEY (`id`)" +
|
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;"
|
|
_, err := tx.Exec(sqlStatement)
|
|
return err
|
|
}
|
|
|
|
func Down_20161118212515(tx *sql.Tx) error {
|
|
_, err := tx.Exec("DROP TABLE IF EXISTS `distributed_query_executions`;")
|
|
return err
|
|
}
|