mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
parent
9f43d5c647
commit
a284332a91
2 changed files with 24 additions and 1 deletions
|
@ -19,7 +19,7 @@ func SQLite(tx *sql.Tx) *MigrationDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sqliteDriver) CreateTable(tableName string, args []string) (sql.Result, error) {
|
func (s *sqliteDriver) CreateTable(tableName string, args []string) (sql.Result, error) {
|
||||||
return s.Tx.Exec(fmt.Sprintf("CREATE TABLE %s (%s)", tableName, strings.Join(args, ", ")))
|
return s.Tx.Exec(fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (%s)", tableName, strings.Join(args, ", ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sqliteDriver) RenameTable(tableName, newName string) (sql.Result, error) {
|
func (s *sqliteDriver) RenameTable(tableName, newName string) (sql.Result, error) {
|
||||||
|
|
|
@ -290,6 +290,29 @@ func TestMigrateCreateTable(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMigrateExistingCreateTable(t *testing.T) {
|
||||||
|
defer tearDown()
|
||||||
|
if err := setUp(); err != nil {
|
||||||
|
t.Fatalf("Error preparing database: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.Exec(testSchema); err != nil {
|
||||||
|
t.Fatalf("Can not create database: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mgr := New(db)
|
||||||
|
rev := &revision1{}
|
||||||
|
if err := mgr.Add(rev).Migrate(); err != nil {
|
||||||
|
t.Fatalf("Can not migrate: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var current int64
|
||||||
|
db.QueryRow("SELECT max(revision) FROM migration").Scan(¤t)
|
||||||
|
if current != rev.Revision() {
|
||||||
|
t.Fatalf("Did not successfully migrate")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMigrateRenameTable(t *testing.T) {
|
func TestMigrateRenameTable(t *testing.T) {
|
||||||
defer tearDown()
|
defer tearDown()
|
||||||
if err := setUp(); err != nil {
|
if err := setUp(); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue