MCPcopy
hub / github.com/dnote/dnote / execute

Function execute

pkg/cli/migrate/migrate.go:100–130  ·  view source on GitHub ↗
(ctx context.DnoteCtx, m migration, schemaKey string)

Source from the content-addressed store, hash-verified

98}
99
100func execute(ctx context.DnoteCtx, m migration, schemaKey string) error {
101 log.Debug("running migration %s\n", m.name)
102
103 tx, err := ctx.DB.Begin()
104 if err != nil {
105 return errors.Wrap(err, "beginning a transaction")
106 }
107
108 err = m.run(ctx, tx)
109 if err != nil {
110 tx.Rollback()
111 return errors.Wrapf(err, "running '%s'", m.name)
112 }
113
114 var currentSchema int
115 err = tx.QueryRow("SELECT value FROM system WHERE key = ?", schemaKey).Scan(&currentSchema)
116 if err != nil {
117 tx.Rollback()
118 return errors.Wrap(err, "getting current schema")
119 }
120
121 _, err = tx.Exec("UPDATE system SET value = value + 1 WHERE key = ?", schemaKey)
122 if err != nil {
123 tx.Rollback()
124 return errors.Wrap(err, "incrementing schema")
125 }
126
127 tx.Commit()
128
129 return nil
130}
131
132// Run performs unrun migrations
133func Run(ctx context.DnoteCtx, migrations []migration, mode int) error {

Callers 2

TestExecute_bump_schemaFunction · 0.85
RunFunction · 0.85

Calls 6

DebugFunction · 0.92
BeginMethod · 0.65
RollbackMethod · 0.65
QueryRowMethod · 0.65
ExecMethod · 0.65
CommitMethod · 0.65

Tested by 1

TestExecute_bump_schemaFunction · 0.68