MCPcopy Index your code
hub / github.com/coder/coder / Version

Method Version

coderd/database/migrations/txnmigrator.go:115–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113}
114
115func (d *pgTxnDriver) Version() (version int, dirty bool, err error) {
116 // If the transaction is valid (we hold the exclusive lock), use the txn for
117 // the query.
118 var q interface {
119 QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
120 } = d.tx
121 // If we don't hold the lock just use the database. This only happens in the
122 // `Stepper` function and is only used in tests.
123 if d.tx == nil {
124 q = d.db
125 }
126
127 query := `SELECT version, dirty FROM ` + migrationsTableName + ` LIMIT 1`
128 err = q.QueryRowContext(context.Background(), query).Scan(&version, &dirty)
129 switch {
130 case err == sql.ErrNoRows:
131 return database.NilVersion, false, nil
132
133 case err != nil:
134 var pgErr *pq.Error
135 if xerrors.As(err, &pgErr) {
136 if pgErr.Code.Name() == "undefined_table" {
137 return database.NilVersion, false, nil
138 }
139 }
140 return 0, false, &database.Error{OrigErr: err, Query: []byte(query)}
141
142 default:
143 return version, dirty, nil
144 }
145}
146
147func (*pgTxnDriver) Drop() error {
148 panic("not implemented")

Callers 9

DynamicParameterTemplateFunction · 0.80
openEmbeddedPostgresFunction · 0.80
EnsureCleanFunction · 0.80
StepperFunction · 0.80
GetNetworkingStackFunction · 0.80
startBuiltinPostgresFunction · 0.80
startTempPostgresSetURLFunction · 0.80
startServerDebugFunction · 0.80
mainFunction · 0.80

Calls 4

QueryRowContextMethod · 0.80
AsMethod · 0.80
NameMethod · 0.65
ScanMethod · 0.45

Tested by

no test coverage detected