How to use Type method of migrator Package

Best Testkube code snippet using migrator.Type

tables.go

Source:tables.go Github

copy

Full Screen

...22 mg.AddMigration("delete alert_definition table", migrator.NewDropTableMigration("alert_definition"))23 alertDefinition := migrator.Table{24 Name: "alert_definition",25 Columns: []*migrator.Column{26 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},27 {Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},28 {Name: "title", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},29 {Name: "condition", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},30 {Name: "data", Type: migrator.DB_Text, Nullable: false},31 {Name: "updated", Type: migrator.DB_DateTime, Nullable: false},32 {Name: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false, Default: fmt.Sprintf("%d", defaultIntervalSeconds)},33 {Name: "version", Type: migrator.DB_Int, Nullable: false, Default: "0"},34 {Name: "uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false, Default: "0"},35 },36 Indices: []*migrator.Index{37 {Cols: []string{"org_id", "title"}, Type: migrator.IndexType},38 {Cols: []string{"org_id", "uid"}, Type: migrator.IndexType},39 },40 }41 // create table42 mg.AddMigration("recreate alert_definition table", migrator.NewAddTableMigration(alertDefinition))43 // create indices44 mg.AddMigration("add index in alert_definition on org_id and title columns", migrator.NewAddIndexMigration(alertDefinition, alertDefinition.Indices[0]))45 mg.AddMigration("add index in alert_definition on org_id and uid columns", migrator.NewAddIndexMigration(alertDefinition, alertDefinition.Indices[1]))46 mg.AddMigration("alter alert_definition table data column to mediumtext in mysql", migrator.NewRawSQLMigration("").47 Mysql("ALTER TABLE alert_definition MODIFY data MEDIUMTEXT;"))48 mg.AddMigration("drop index in alert_definition on org_id and title columns", migrator.NewDropIndexMigration(alertDefinition, alertDefinition.Indices[0]))49 mg.AddMigration("drop index in alert_definition on org_id and uid columns", migrator.NewDropIndexMigration(alertDefinition, alertDefinition.Indices[1]))50 uniqueIndices := []*migrator.Index{51 {Cols: []string{"org_id", "title"}, Type: migrator.UniqueIndex},52 {Cols: []string{"org_id", "uid"}, Type: migrator.UniqueIndex},53 }54 mg.AddMigration("add unique index in alert_definition on org_id and title columns", migrator.NewAddIndexMigration(alertDefinition, uniqueIndices[0]))55 mg.AddMigration("add unique index in alert_definition on org_id and uid columns", migrator.NewAddIndexMigration(alertDefinition, uniqueIndices[1]))56 mg.AddMigration("Add column paused in alert_definition", migrator.NewAddColumnMigration(alertDefinition, &migrator.Column{57 Name: "paused", Type: migrator.DB_Bool, Nullable: false, Default: "0",58 }))59 mg.AddMigration("drop alert_definition table", migrator.NewDropTableMigration("alert_definition"))60}61// AddAlertDefinitionMigrations should not be modified.62func AddAlertDefinitionVersionMigrations(mg *migrator.Migrator) {63 mg.AddMigration("delete alert_definition_version table", migrator.NewDropTableMigration("alert_definition_version"))64 alertDefinitionVersion := migrator.Table{65 Name: "alert_definition_version",66 Columns: []*migrator.Column{67 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},68 {Name: "alert_definition_id", Type: migrator.DB_BigInt},69 {Name: "alert_definition_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false, Default: "0"},70 {Name: "parent_version", Type: migrator.DB_Int, Nullable: false},71 {Name: "restored_from", Type: migrator.DB_Int, Nullable: false},72 {Name: "version", Type: migrator.DB_Int, Nullable: false},73 {Name: "created", Type: migrator.DB_DateTime, Nullable: false},74 {Name: "title", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},75 {Name: "condition", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},76 {Name: "data", Type: migrator.DB_Text, Nullable: false},77 {Name: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false},78 },79 Indices: []*migrator.Index{80 {Cols: []string{"alert_definition_id", "version"}, Type: migrator.UniqueIndex},81 {Cols: []string{"alert_definition_uid", "version"}, Type: migrator.UniqueIndex},82 },83 }84 mg.AddMigration("recreate alert_definition_version table", migrator.NewAddTableMigration(alertDefinitionVersion))85 mg.AddMigration("add index in alert_definition_version table on alert_definition_id and version columns", migrator.NewAddIndexMigration(alertDefinitionVersion, alertDefinitionVersion.Indices[0]))86 mg.AddMigration("add index in alert_definition_version table on alert_definition_uid and version columns", migrator.NewAddIndexMigration(alertDefinitionVersion, alertDefinitionVersion.Indices[1]))87 mg.AddMigration("alter alert_definition_version table data column to mediumtext in mysql", migrator.NewRawSQLMigration("").88 Mysql("ALTER TABLE alert_definition_version MODIFY data MEDIUMTEXT;"))89 mg.AddMigration("drop alert_definition_version table", migrator.NewDropTableMigration("alert_definition_version"))90}91func AlertInstanceMigration(mg *migrator.Migrator) {92 alertInstance := migrator.Table{93 Name: "alert_instance",94 Columns: []*migrator.Column{95 {Name: "def_org_id", Type: migrator.DB_BigInt, Nullable: false},96 {Name: "def_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false, Default: "0"},97 {Name: "labels", Type: migrator.DB_Text, Nullable: false},98 {Name: "labels_hash", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},99 {Name: "current_state", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},100 {Name: "current_state_since", Type: migrator.DB_BigInt, Nullable: false},101 {Name: "last_eval_time", Type: migrator.DB_BigInt, Nullable: false},102 },103 PrimaryKeys: []string{"def_org_id", "def_uid", "labels_hash"},104 Indices: []*migrator.Index{105 {Cols: []string{"def_org_id", "def_uid", "current_state"}, Type: migrator.IndexType},106 {Cols: []string{"def_org_id", "current_state"}, Type: migrator.IndexType},107 },108 }109 // create table110 mg.AddMigration("create alert_instance table", migrator.NewAddTableMigration(alertInstance))111 mg.AddMigration("add index in alert_instance table on def_org_id, def_uid and current_state columns", migrator.NewAddIndexMigration(alertInstance, alertInstance.Indices[0]))112 mg.AddMigration("add index in alert_instance table on def_org_id, current_state columns", migrator.NewAddIndexMigration(alertInstance, alertInstance.Indices[1]))113 mg.AddMigration("add column current_state_end to alert_instance", migrator.NewAddColumnMigration(alertInstance, &migrator.Column{114 Name: "current_state_end", Type: migrator.DB_BigInt, Nullable: false, Default: "0",115 }))116 mg.AddMigration("remove index def_org_id, def_uid, current_state on alert_instance", migrator.NewDropIndexMigration(alertInstance, alertInstance.Indices[0]))117 mg.AddMigration("remove index def_org_id, current_state on alert_instance", migrator.NewDropIndexMigration(alertInstance, alertInstance.Indices[1]))118 mg.AddMigration("rename def_org_id to rule_org_id in alert_instance", migrator.NewRawSQLMigration("").119 Default("ALTER TABLE alert_instance RENAME COLUMN def_org_id TO rule_org_id;").120 Mysql("ALTER TABLE alert_instance CHANGE def_org_id rule_org_id BIGINT;"))121 mg.AddMigration("rename def_uid to rule_uid in alert_instance", migrator.NewRawSQLMigration("").122 Default("ALTER TABLE alert_instance RENAME COLUMN def_uid TO rule_uid;").123 Mysql("ALTER TABLE alert_instance CHANGE def_uid rule_uid VARCHAR(40);"))124 mg.AddMigration("add index rule_org_id, rule_uid, current_state on alert_instance", migrator.NewAddIndexMigration(alertInstance, &migrator.Index{125 Cols: []string{"rule_org_id", "rule_uid", "current_state"}, Type: migrator.IndexType,126 }))127 mg.AddMigration("add index rule_org_id, current_state on alert_instance", migrator.NewAddIndexMigration(alertInstance, &migrator.Index{128 Cols: []string{"rule_org_id", "current_state"}, Type: migrator.IndexType,129 }))130}131func AddAlertRuleMigrations(mg *migrator.Migrator, defaultIntervalSeconds int64) {132 alertRule := migrator.Table{133 Name: "alert_rule",134 Columns: []*migrator.Column{135 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},136 {Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},137 {Name: "title", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},138 {Name: "condition", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},139 {Name: "data", Type: migrator.DB_Text, Nullable: false},140 {Name: "updated", Type: migrator.DB_DateTime, Nullable: false},141 {Name: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false, Default: fmt.Sprintf("%d", defaultIntervalSeconds)},142 {Name: "version", Type: migrator.DB_Int, Nullable: false, Default: "0"},143 {Name: "uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false, Default: "0"},144 // the following fields will correspond to a dashboard (or folder) UIID145 {Name: "namespace_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false},146 {Name: "rule_group", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},147 {Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'NoData'"},148 {Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'Alerting'"},149 },150 Indices: []*migrator.Index{151 {Cols: []string{"org_id", "title"}, Type: migrator.UniqueIndex},152 {Cols: []string{"org_id", "uid"}, Type: migrator.UniqueIndex},153 {Cols: []string{"org_id", "namespace_uid", "rule_group"}, Type: migrator.IndexType},154 },155 }156 // create table157 mg.AddMigration("create alert_rule table", migrator.NewAddTableMigration(alertRule))158 // create indices159 mg.AddMigration("add index in alert_rule on org_id and title columns", migrator.NewAddIndexMigration(alertRule, alertRule.Indices[0]))160 mg.AddMigration("add index in alert_rule on org_id and uid columns", migrator.NewAddIndexMigration(alertRule, alertRule.Indices[1]))161 mg.AddMigration("add index in alert_rule on org_id, namespace_uid, group_uid columns", migrator.NewAddIndexMigration(alertRule, alertRule.Indices[2]))162 mg.AddMigration("alter alert_rule table data column to mediumtext in mysql", migrator.NewRawSQLMigration("").163 Mysql("ALTER TABLE alert_rule MODIFY data MEDIUMTEXT;"))164 // add for column165 mg.AddMigration("add column for to alert_rule", migrator.NewAddColumnMigration(alertRule, &migrator.Column{Name: "for", Type: migrator.DB_BigInt, Nullable: false, Default: "0"}))166 // add annotations column167 mg.AddMigration("add column annotations to alert_rule", migrator.NewAddColumnMigration(alertRule, &migrator.Column{Name: "annotations", Type: migrator.DB_Text, Nullable: true}))168 // add labels column169 mg.AddMigration("add column labels to alert_rule", migrator.NewAddColumnMigration(alertRule, &migrator.Column{Name: "labels", Type: migrator.DB_Text, Nullable: true}))170 mg.AddMigration("remove unique index from alert_rule on org_id, title columns", migrator.NewDropIndexMigration(alertRule, &migrator.Index{171 Cols: []string{"org_id", "title"}, Type: migrator.UniqueIndex,172 }))173 mg.AddMigration("add index in alert_rule on org_id, namespase_uid and title columns", migrator.NewAddIndexMigration(alertRule, &migrator.Index{174 Cols: []string{"org_id", "namespace_uid", "title"}, Type: migrator.UniqueIndex,175 }))176 mg.AddMigration("add dashboard_uid column to alert_rule", migrator.NewAddColumnMigration(177 migrator.Table{Name: "alert_rule"},178 &migrator.Column{179 Name: "dashboard_uid",180 Type: migrator.DB_NVarchar,181 Length: 40,182 Nullable: true,183 },184 ))185 mg.AddMigration("add panel_id column to alert_rule", migrator.NewAddColumnMigration(186 migrator.Table{Name: "alert_rule"},187 &migrator.Column{188 Name: "panel_id",189 Type: migrator.DB_BigInt,190 Nullable: true,191 },192 ))193 mg.AddMigration("add index in alert_rule on org_id, dashboard_uid and panel_id columns", migrator.NewAddIndexMigration(194 migrator.Table{Name: "alert_rule"},195 &migrator.Index{196 Name: "IDX_alert_rule_org_id_dashboard_uid_panel_id",197 Cols: []string{"org_id", "dashboard_uid", "panel_id"},198 },199 ))200}201func AddAlertRuleVersionMigrations(mg *migrator.Migrator) {202 alertRuleVersion := migrator.Table{203 Name: "alert_rule_version",204 Columns: []*migrator.Column{205 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},206 {Name: "rule_org_id", Type: migrator.DB_BigInt},207 {Name: "rule_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false, Default: "0"},208 // the following fields will correspond to a dashboard (or folder) UID209 {Name: "rule_namespace_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false},210 {Name: "rule_group", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},211 {Name: "parent_version", Type: migrator.DB_Int, Nullable: false},212 {Name: "restored_from", Type: migrator.DB_Int, Nullable: false},213 {Name: "version", Type: migrator.DB_Int, Nullable: false},214 {Name: "created", Type: migrator.DB_DateTime, Nullable: false},215 {Name: "title", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},216 {Name: "condition", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},217 {Name: "data", Type: migrator.DB_Text, Nullable: false},218 {Name: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false},219 {Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'NoData'"},220 {Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'Alerting'"},221 },222 Indices: []*migrator.Index{223 {Cols: []string{"rule_org_id", "rule_uid", "version"}, Type: migrator.UniqueIndex},224 {Cols: []string{"rule_org_id", "rule_namespace_uid", "rule_group"}, Type: migrator.IndexType},225 },226 }227 mg.AddMigration("create alert_rule_version table", migrator.NewAddTableMigration(alertRuleVersion))228 mg.AddMigration("add index in alert_rule_version table on rule_org_id, rule_uid and version columns", migrator.NewAddIndexMigration(alertRuleVersion, alertRuleVersion.Indices[0]))229 mg.AddMigration("add index in alert_rule_version table on rule_org_id, rule_namespace_uid and rule_group columns", migrator.NewAddIndexMigration(alertRuleVersion, alertRuleVersion.Indices[1]))230 mg.AddMigration("alter alert_rule_version table data column to mediumtext in mysql", migrator.NewRawSQLMigration("").231 Mysql("ALTER TABLE alert_rule_version MODIFY data MEDIUMTEXT;"))232 // add for column233 mg.AddMigration("add column for to alert_rule_version", migrator.NewAddColumnMigration(alertRuleVersion, &migrator.Column{Name: "for", Type: migrator.DB_BigInt, Nullable: false, Default: "0"}))234 // add annotations column235 mg.AddMigration("add column annotations to alert_rule_version", migrator.NewAddColumnMigration(alertRuleVersion, &migrator.Column{Name: "annotations", Type: migrator.DB_Text, Nullable: true}))236 // add labels column237 mg.AddMigration("add column labels to alert_rule_version", migrator.NewAddColumnMigration(alertRuleVersion, &migrator.Column{Name: "labels", Type: migrator.DB_Text, Nullable: true}))238}239func AddAlertmanagerConfigMigrations(mg *migrator.Migrator) {240 alertConfiguration := migrator.Table{241 Name: "alert_configuration",242 Columns: []*migrator.Column{243 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},244 {Name: "alertmanager_configuration", Type: migrator.DB_Text, Nullable: false},245 {Name: "configuration_version", Type: migrator.DB_NVarchar, Length: 3}, // In a format of vXX e.g. v1, v2, v10, etc246 {Name: "created_at", Type: migrator.DB_Int, Nullable: false},247 },248 }249 mg.AddMigration("create_alert_configuration_table", migrator.NewAddTableMigration(alertConfiguration))250 mg.AddMigration("Add column default in alert_configuration", migrator.NewAddColumnMigration(alertConfiguration, &migrator.Column{251 Name: "default", Type: migrator.DB_Bool, Nullable: false, Default: "0",252 }))253 mg.AddMigration("alert alert_configuration alertmanager_configuration column from TEXT to MEDIUMTEXT if mysql", migrator.NewRawSQLMigration("").254 Mysql("ALTER TABLE alert_configuration MODIFY alertmanager_configuration MEDIUMTEXT;"))255 mg.AddMigration("add column org_id in alert_configuration", migrator.NewAddColumnMigration(alertConfiguration, &migrator.Column{256 Name: "org_id", Type: migrator.DB_BigInt, Nullable: false, Default: "0",257 }))258 // add index on org_id259 mg.AddMigration("add index in alert_configuration table on org_id column", migrator.NewAddIndexMigration(alertConfiguration, &migrator.Index{260 Cols: []string{"org_id"},261 }))262}263func AddAlertAdminConfigMigrations(mg *migrator.Migrator) {264 adminConfiguration := migrator.Table{265 Name: "ngalert_configuration",266 Columns: []*migrator.Column{267 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},268 {Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},269 {Name: "alertmanagers", Type: migrator.DB_Text, Nullable: true},270 {Name: "created_at", Type: migrator.DB_Int, Nullable: false},271 {Name: "updated_at", Type: migrator.DB_Int, Nullable: false},272 },273 Indices: []*migrator.Index{274 {Cols: []string{"org_id"}, Type: migrator.UniqueIndex},275 },276 }277 mg.AddMigration("create_ngalert_configuration_table", migrator.NewAddTableMigration(adminConfiguration))278 mg.AddMigration("add index in ngalert_configuration on org_id column", migrator.NewAddIndexMigration(adminConfiguration, adminConfiguration.Indices[0]))279}...

Full Screen

Full Screen

migrations.go

Source:migrations.go Github

copy

Full Screen

...3func AddMigration(mg *migrator.Migrator) {4 permissionV1 := migrator.Table{5 Name: "permission",6 Columns: []*migrator.Column{7 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},8 {Name: "role_id", Type: migrator.DB_BigInt},9 {Name: "action", Type: migrator.DB_Varchar, Length: 190, Nullable: false},10 {Name: "scope", Type: migrator.DB_Varchar, Length: 190, Nullable: false},11 {Name: "created", Type: migrator.DB_DateTime, Nullable: false},12 {Name: "updated", Type: migrator.DB_DateTime, Nullable: false},13 },14 Indices: []*migrator.Index{15 {Cols: []string{"role_id"}},16 {Cols: []string{"role_id", "action", "scope"}, Type: migrator.UniqueIndex},17 },18 }19 mg.AddMigration("create permission table", migrator.NewAddTableMigration(permissionV1))20 //------- indexes ------------------21 mg.AddMigration("add unique index permission.role_id", migrator.NewAddIndexMigration(permissionV1, permissionV1.Indices[0]))22 mg.AddMigration("add unique index role_id_action_scope", migrator.NewAddIndexMigration(permissionV1, permissionV1.Indices[1]))23 roleV1 := migrator.Table{24 Name: "role",25 Columns: []*migrator.Column{26 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},27 {Name: "name", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},28 {Name: "description", Type: migrator.DB_Text, Nullable: true},29 {Name: "version", Type: migrator.DB_BigInt, Nullable: false},30 {Name: "org_id", Type: migrator.DB_BigInt},31 {Name: "uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false},32 {Name: "created", Type: migrator.DB_DateTime, Nullable: false},33 {Name: "updated", Type: migrator.DB_DateTime, Nullable: false},34 },35 Indices: []*migrator.Index{36 {Cols: []string{"org_id"}},37 {Cols: []string{"org_id", "name"}, Type: migrator.UniqueIndex},38 {Cols: []string{"org_id", "uid"}, Type: migrator.UniqueIndex},39 },40 }41 mg.AddMigration("create role table", migrator.NewAddTableMigration(roleV1))42 mg.AddMigration("add column display_name", migrator.NewAddColumnMigration(roleV1, &migrator.Column{43 Name: "display_name", Type: migrator.DB_NVarchar, Length: 190, Nullable: true,44 }))45 mg.AddMigration("add column group_name", migrator.NewAddColumnMigration(roleV1, &migrator.Column{46 Name: "group_name", Type: migrator.DB_NVarchar, Length: 190, Nullable: true,47 }))48 //------- indexes ------------------49 mg.AddMigration("add index role.org_id", migrator.NewAddIndexMigration(roleV1, roleV1.Indices[0]))50 mg.AddMigration("add unique index role_org_id_name", migrator.NewAddIndexMigration(roleV1, roleV1.Indices[1]))51 mg.AddMigration("add index role_org_id_uid", migrator.NewAddIndexMigration(roleV1, roleV1.Indices[2]))52 teamRoleV1 := migrator.Table{53 Name: "team_role",54 Columns: []*migrator.Column{55 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},56 {Name: "org_id", Type: migrator.DB_BigInt},57 {Name: "team_id", Type: migrator.DB_BigInt},58 {Name: "role_id", Type: migrator.DB_BigInt},59 {Name: "created", Type: migrator.DB_DateTime, Nullable: false},60 },61 Indices: []*migrator.Index{62 {Cols: []string{"org_id"}},63 {Cols: []string{"org_id", "team_id", "role_id"}, Type: migrator.UniqueIndex},64 {Cols: []string{"team_id"}},65 },66 }67 mg.AddMigration("create team role table", migrator.NewAddTableMigration(teamRoleV1))68 //------- indexes ------------------69 mg.AddMigration("add index team_role.org_id", migrator.NewAddIndexMigration(teamRoleV1, teamRoleV1.Indices[0]))70 mg.AddMigration("add unique index team_role_org_id_team_id_role_id", migrator.NewAddIndexMigration(teamRoleV1, teamRoleV1.Indices[1]))71 mg.AddMigration("add index team_role.team_id", migrator.NewAddIndexMigration(teamRoleV1, teamRoleV1.Indices[2]))72 userRoleV1 := migrator.Table{73 Name: "user_role",74 Columns: []*migrator.Column{75 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},76 {Name: "org_id", Type: migrator.DB_BigInt},77 {Name: "user_id", Type: migrator.DB_BigInt},78 {Name: "role_id", Type: migrator.DB_BigInt},79 {Name: "created", Type: migrator.DB_DateTime, Nullable: false},80 },81 Indices: []*migrator.Index{82 {Cols: []string{"org_id"}},83 {Cols: []string{"org_id", "user_id", "role_id"}, Type: migrator.UniqueIndex},84 {Cols: []string{"user_id"}},85 },86 }87 mg.AddMigration("create user role table", migrator.NewAddTableMigration(userRoleV1))88 //------- indexes ------------------89 mg.AddMigration("add index user_role.org_id", migrator.NewAddIndexMigration(userRoleV1, userRoleV1.Indices[0]))90 mg.AddMigration("add unique index user_role_org_id_user_id_role_id", migrator.NewAddIndexMigration(userRoleV1, userRoleV1.Indices[1]))91 mg.AddMigration("add index user_role.user_id", migrator.NewAddIndexMigration(userRoleV1, userRoleV1.Indices[2]))92 builtinRoleV1 := migrator.Table{93 Name: "builtin_role",94 Columns: []*migrator.Column{95 {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},96 {Name: "role", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},97 {Name: "role_id", Type: migrator.DB_BigInt},98 {Name: "created", Type: migrator.DB_DateTime, Nullable: false},99 {Name: "updated", Type: migrator.DB_DateTime, Nullable: false},100 },101 Indices: []*migrator.Index{102 {Cols: []string{"role_id"}},103 {Cols: []string{"role"}},104 },105 }106 mg.AddMigration("create builtin role table", migrator.NewAddTableMigration(builtinRoleV1))107 //------- indexes ------------------108 mg.AddMigration("add index builtin_role.role_id", migrator.NewAddIndexMigration(builtinRoleV1, builtinRoleV1.Indices[0]))109 mg.AddMigration("add index builtin_role.name", migrator.NewAddIndexMigration(builtinRoleV1, builtinRoleV1.Indices[1]))110 // Add org_id column to the builtin_role table111 mg.AddMigration("Add column org_id to builtin_role table", migrator.NewAddColumnMigration(builtinRoleV1, &migrator.Column{112 Name: "org_id", Type: migrator.DB_BigInt, Default: "0",113 }))114 mg.AddMigration("add index builtin_role.org_id", migrator.NewAddIndexMigration(builtinRoleV1, &migrator.Index{115 Cols: []string{"org_id"},116 }))117 mg.AddMigration("add unique index builtin_role_org_id_role_id_role", migrator.NewAddIndexMigration(builtinRoleV1, &migrator.Index{118 Cols: []string{"org_id", "role_id", "role"}, Type: migrator.UniqueIndex,119 }))120 // Make role.uid unique across Grafana instance121 mg.AddMigration("Remove unique index role_org_id_uid", migrator.NewDropIndexMigration(roleV1, &migrator.Index{122 Cols: []string{"org_id", "uid"}, Type: migrator.UniqueIndex,123 }))124 mg.AddMigration("add unique index role.uid", migrator.NewAddIndexMigration(roleV1, &migrator.Index{125 Cols: []string{"uid"}, Type: migrator.UniqueIndex,126 }))127 seedAssignmentV1 := migrator.Table{128 Name: "seed_assignment",129 Columns: []*migrator.Column{130 {Name: "builtin_role", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},131 {Name: "role_name", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},132 },133 Indices: []*migrator.Index{134 {Cols: []string{"builtin_role", "role_name"}, Type: migrator.UniqueIndex},135 },136 }137 mg.AddMigration("create seed assignment table", migrator.NewAddTableMigration(seedAssignmentV1))138 //------- indexes ------------------139 mg.AddMigration("add unique index builtin_role_role_name", migrator.NewAddIndexMigration(seedAssignmentV1, seedAssignmentV1.Indices[0]))140}...

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1migrator.Type("users", func(table table) {2table.increments("id")3table.string("name")4table.timestamps()5})6migrator.RenameColumn("users", "is_admin", "is_operator")7migrator.RenameTable("users", "admin_users")8migrator.DropColumn("users", "votes")9migrator.DropTable("users")10migrator.DropTableIfExists("users")11migrator.DropColumnIfExists("users", "votes")12migrator.HasColumn("users", "votes")13migrator.HasTable("users")14migrator.Table("users")15migrator.Columns("users")16migrator.PrimaryKey("users")17migrator.HasTable("users")18migrator.HasColumn("users", "votes")19migrator.RenameColumn("users", "is_admin", "is_operator")20migrator.ModifyColumn("users", "votes", column{21})

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(m1.Type)4}5import "fmt"6func main() {7 fmt.Println(m1.Type())8}9import "fmt"10func main() {11 fmt.Println(m1.Type())12}13import "fmt"14func main() {15 fmt.Println(m1.Type())16}17import "fmt"18func main() {19 fmt.Println(m1.Type())20}21import "fmt"22func main() {23 fmt.Println(m1.Type())24}25import "fmt"26func main() {27 fmt.Println(m1.Type())28}29import "fmt"30func main() {31 fmt.Println(m1.Type())32}33import "fmt"34func main() {

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1migrator.Type( "TypeA" , func( m *migrator.Migrator ) {2 m.CreateTable( "table1" , func( t *migrator.Table ) {3 t.Column( "id" , "int" )4 t.Column( "name" , "string" )5 t.PrimaryKey( "id" )6 })7})8migrator.Type( "TypeB" , func( m *migrator.Migrator ) {9 m.CreateTable( "table2" , func( t *migrator.Table ) {10 t.Column( "id" , "int" )11 t.Column( "name" , "string" )12 t.PrimaryKey( "id" )13 })14})15import (16type TypeA_20191212_181426 struct {17}18func init() {19 m := &TypeA_20191212_181426{}20 migration.Register( "TypeA_20191212_181426" , m)21}22func (m *TypeA_20191212_181426) Up() {23 m.CreateTable( "table1" , func( t *migrator.Table ) {24 t.Column( "id" , "int" )25 t.Column( "name" , "string" )26 t.PrimaryKey( "id" )27 })28}29func (m *TypeA_20191212_181426) Down() {30 m.DropTable( "table1" )31}32import (33type TypeB_20191212_181426 struct {34}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful