Open theoriginalstove opened 2 months ago
@a8m from the discord discussion regarding triggers in cockroachdb https://discord.com/channels/930720389120794674/933360123357839360/1270638827454730373
Was digging around the sql/postgres
driver and found the error is propagating up from this block in sql/postgres/driver.go
when calling d.InspectSchema(ctx, d.schema, nil)
:
// Snapshot implements migrate.Snapshoter.
func (d *Driver) Snapshot(ctx context.Context) (migrate.RestoreFunc, error) {
// Postgres will only then be considered bound to a schema if the `search_path` was given.
// In all other cases, the connection is considered bound to the realm.
if d.schema != "" {
s, err := d.InspectSchema(ctx, d.schema, nil)
if err != nil {
return nil, err
}
if len(s.Tables) > 0 {
return nil, &migrate.NotCleanError{
State: schema.NewRealm(s),
Reason: fmt.Sprintf("found table %q in connected schema", s.Tables[0].Name),
}
}
return d.SchemaRestoreFunc(s), nil
}
Which led me to test logging out of the atlas cli and running the command. Running it while logged out of atlas cloud, the command will run successfully (or in my case give another error because I'm trying to create migrations with multiple .sql
files in a declarative manner)
My guess is that the query being ran against cockroachdb are trying to execute a Postgres function that hasn't been ported over to cockroach. Running the commands while logged in, but against earlier versions of cockroach would error out with Error: sql/migrate: taking database snapshot: query functions: pq: unknown function: pg_get_function_arg_default(): function undefined
which pg_get_function_arg_default()
was added in cockroach v23.2 based off their documentation.
Running the commands
atlas migrate
oratlas schema
when trying to create either declarative or versioned migration workflows will result in an error:Error: sql/migrate: taking database snapshot: query triggers: pq: unknown function: regexp_match()
Steps to reproduce:
schemas.sql
:atlas schema
oratlas migrate