MCPcopy
hub / github.com/apache/devlake / Execute

Method Execute

backend/core/migration/migrator.go:89–116  ·  view source on GitHub ↗

Execute all registered migration script in order and mark them as executed in migration_history table

()

Source from the content-addressed store, hash-verified

87
88// Execute all registered migration script in order and mark them as executed in migration_history table
89func (m *migratorImpl) Execute() errors.Error {
90 // sort the scripts by version
91 sort.Slice(m.pending, func(i, j int) bool {
92 return m.pending[i].script.Version() < m.pending[j].script.Version()
93 })
94 m.Info("Execute")
95 // execute them one by one
96 db := m.basicRes.GetDal()
97 for _, swc := range m.pending {
98 scriptId := getScriptId(swc.script.Name(), swc.script.Version())
99 m.logger.Info("applying migration script %s", scriptId)
100 err := swc.script.Up(m.basicRes)
101 if err != nil {
102 return err
103 }
104 err = db.Create(&MigrationHistory{
105 ScriptVersion: swc.script.Version(),
106 ScriptName: swc.script.Name(),
107 Comment: swc.comment,
108 })
109 if err != nil {
110 return errors.Default.Wrap(err, fmt.Sprintf("failed to execute migration script %s", scriptId))
111 }
112 m.executed[scriptId] = true
113 m.pending = m.pending[1:]
114 }
115 return nil
116}
117
118// HasPendingScripts returns if there is any pending migration scripts
119func (m *migratorImpl) HasPendingScripts() bool {

Callers

nothing calls this directly

Calls 9

InfoMethod · 0.95
getScriptIdFunction · 0.85
WrapMethod · 0.80
VersionMethod · 0.65
GetDalMethod · 0.65
NameMethod · 0.65
InfoMethod · 0.65
UpMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected