Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Save SQL content in db
Browse files Browse the repository at this point in the history
  • Loading branch information
kmikiy committed Mar 31, 2021
1 parent f842348 commit 9ab7257
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func SetIgnoreUnknown(v bool) {

type Migration struct {
Id string
SQL string
Up []string
Down []string

Expand Down Expand Up @@ -167,8 +168,9 @@ func (b byId) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b byId) Less(i, j int) bool { return b[i].Less(b[j]) }

type MigrationRecord struct {
Id string `db:"id"`
AppliedAt time.Time `db:"applied_at"`
Id string `db:"id"`
AppliedAt time.Time `db:"applied_at"`
MigrationSQL string `db:"migration_sql"`
}

type OracleDialect struct {
Expand Down Expand Up @@ -392,8 +394,15 @@ func (p PackrMigrationSource) FindMigrations() ([]*Migration, error) {

// Migration parsing
func ParseMigration(id string, r io.ReadSeeker) (*Migration, error) {
r1, err := io.ReadAll(r)
if err != nil {
return nil, err
}
r.Seek(0, io.SeekStart)

m := &Migration{
Id: id,
Id: id,
SQL: string(r1),
}

parsed, err := sqlparse.ParseMigration(r)
Expand Down Expand Up @@ -475,8 +484,9 @@ func (ms MigrationSet) ExecMax(db *sql.DB, dialect string, m MigrationSource, di
switch dir {
case Up:
err = executor.Insert(&MigrationRecord{
Id: migration.Id,
AppliedAt: time.Now(),
Id: migration.Id,
AppliedAt: time.Now(),
MigrationSQL: migration.Migration.SQL,
})
if err != nil {
if trans, ok := executor.(*gorp.Transaction); ok {
Expand Down

0 comments on commit 9ab7257

Please sign in to comment.