Skip to content

Commit 024389b

Browse files
authored
Merge pull request #2 from danielmorell/set
Updated Migrator.names to map[string]struct{}
2 parents e36e1b1 + 5e9a010 commit 024389b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

sqlxm.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type Migrator struct {
111111
// The names of migrations that need the hash repaired.
112112
repair map[string]string
113113
// Set of added migrations
114-
names map[string]bool
114+
names map[string]struct{}
115115
// The query runner for the db.
116116
backend backends.Backend
117117
// The SQL 'table_schema' in Postgres this is typically 'public' in MySQL
@@ -145,11 +145,11 @@ func (m *Migrator) UseBackend(key string) error {
145145
// An error is returned if a migration with the same name has already been
146146
// added.
147147
func (m *Migrator) AddMigration(name string, comment string, statement string, args ...interface{}) error {
148-
if m.names[name] {
148+
if _, ok := m.names[name]; ok {
149149
return fmt.Errorf("migration '%s' alraedy exists", name)
150150
}
151151
// Add name to set
152-
m.names[name] = true
152+
m.names[name] = struct{}{}
153153

154154
// Create the new migration
155155
mig := Migration{
@@ -390,7 +390,7 @@ func New(db *sqlx.DB, tableName string, tableSchema string) (Migrator, error) {
390390
previous: make(map[string]string),
391391
migrations: make([]Migration, 0, 1),
392392
repair: make(map[string]string),
393-
names: make(map[string]bool),
393+
names: make(map[string]struct{}),
394394
}
395395
b := BackendType(db.DriverName())
396396
err := m.UseBackend(b)

0 commit comments

Comments
 (0)