Achieve Rails-style migrations in MS Access VBA application
Posted
by avguchenko
on Stack Overflow
See other posts from Stack Overflow
or by avguchenko
Published on 2010-03-15T20:29:20Z
Indexed on
2010/03/15
20:29 UTC
Read the original article
Hit count: 385
This is a simple way to do Rails-style migrations in a VBA application. Just add additional migrations like migration(name, sql_string, database) to run_migratons and call run_migrations somewhere in the beginning of your execution.
Function migrate(signature As String, sql As String, dbs As DAO.database)
Dim rs As DAO.Recordset
Set rs = dbs.OpenRecordset("select * from versions where migration = '" & signature & "'")
If rs.EOF Then
dbs.Execute (sql)
rs.AddNew
rs("migration") = signature
rs.Update
End If
End Function
Function setup_versions(dbs As DAO.database)
Dim t As DAO.TableDef
On Error Resume Next
Set t = dbs.TableDefs("versions")
If Err.Number <> 0 Then
dbs.Execute ("CREATE TABLE versions (migration text)")
End If
Err.Clear
End Function
Function run_migrations(dbs As DAO.database)
setup_versions(dbs)
migrate("20100315142400_create_table", "CREATE TABLE table_name (field1 type, field 2 type)", dbs)
'add migrations here'
End Function
© Stack Overflow or respective owner