Progress on database schema migration for account -> org refactor

This commit is contained in:
Torkel Ödegaard
2015-02-24 11:46:34 +01:00
parent da41d99aa7
commit 02a89c752b
16 changed files with 595 additions and 193 deletions

View File

@ -20,8 +20,12 @@ type Dialect interface {
CreateIndexSql(tableName string, index *Index) string
CreateTableSql(table *Table) string
AddColumnSql(tableName string, Col *Column) string
CopyTableData(sourceTable string, targetTable string, sourceCols string, targetCols string) string
DropTable(tableName string) string
DropIndexSql(tableName string, index *Index) string
TableCheckSql(tableName string) (string, []interface{})
RenameTable(oldName string, newName string) string
}
func NewDialect(name string) Dialect {
@ -113,3 +117,25 @@ func (db *BaseDialect) CreateIndexSql(tableName string, index *Index) string {
quote(idxName), quote(tableName),
quote(strings.Join(index.Cols, quote(","))))
}
func (db *BaseDialect) CopyTableData(sourceTable string, targetTable string, sourceCols string, targetCols string) string {
quote := db.dialect.Quote
return fmt.Sprintf("INSERT INTO %s (%s) SELECT %s FROM %s", quote(targetTable), targetCols, sourceCols, quote(sourceTable))
}
func (db *BaseDialect) DropTable(tableName string) string {
quote := db.dialect.Quote
return fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName))
}
func (db *BaseDialect) RenameTable(oldName string, newName string) string {
quote := db.dialect.Quote
return fmt.Sprintf("ALTER TABLE %s RENAME TO %s", quote(oldName), quote(newName))
}
func (db *BaseDialect) DropIndexSql(tableName string, index *Index) string {
quote := db.dialect.Quote
var name string
name = index.XName(tableName)
return fmt.Sprintf("DROP INDEX %v ON %s", quote(name), quote(tableName))
}