Ejemplo n.º 1
0
// CreateTables is a helper to create multiple tables in one shot.
// Will return a panic if unable to create a table.
func CreateTables(tables []string) {

	for _, table := range tables {

		exist, err := DoesTableExist(table)
		if err != nil {
			utils.Panicf(
				"Could not verify table %q. Error: %s",
				table,
				err,
			)
		}

		if !exist {
			_, err := CreateTable(table)
			if err != nil {
				utils.Panicf(
					"Unable to create %q table. Error: %s",
					table,
					err,
				)
			}
		}
	}
}
Ejemplo n.º 2
0
// CreateIndices is a helper to create multiple indices in one shot.
// Will return a panic if unable to create an index.
func CreateIndices(tableName string, indices []string) {

	for _, index := range indices {

		indexExist, err := DoesIndexExist(index, tableName)
		if err != nil {
			utils.Panicf(
				"Could not verify index %q for table %q. Error: %s",
				index,
				tableName,
				err,
			)
		}

		if !indexExist {
			_, err := CreateIndex(index, tableName)
			if err != nil {
				utils.Panicf(
					"Unable to create index %q for table %q. Error: %s",
					index,
					tableName,
					err,
				)
			}
		}

	}
}