Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generateion not including the schema name #187

Closed
rkrishnasanka opened this issue Feb 29, 2024 · 2 comments
Closed

Code generateion not including the schema name #187

rkrishnasanka opened this issue Feb 29, 2024 · 2 comments

Comments

@rkrishnasanka
Copy link

So for the following Atlas DDL,

schema "core" {
  comment = "standard public schema"
}

table "tasks" {
    schema = schema.core
    comment = "Table for capturing operational data of task queue"

    column "id" {
        type = bigserial
        null = false
    }

    column "status" {
        type = enum.task_status_enum
        null = false
    }

    column "created_at" {
        type = timestamp
        null = false
        default = sql("CURRENT_TIMESTAMP")
    }

    column "completed_at" {
        type = timestamp
        null = true
    }

    column "payload" {
        // TODO- Change this to type = jsonb
        type = text
        null = true
    }

    column "queue_id" {
        type = bigint
        null = false
    }

    primary_key{
        columns = [column.id]
    }

    foreign_key "fk_task_queue_tasks_id" {
      columns = [column.queue_id]
      ref_columns = [table.queues.column.id]
    }
}

Bob is generating the following line in golang:

// Tasks contains methods to work with the tasks table
var Tasks = psql.NewTablex[*Task, TaskSlice, *TaskSetter]("", "tasks")

it should generate the following line instead:

// Tasks contains methods to work with the tasks table
var Tasks = psql.NewTablex[*Task, TaskSlice, *TaskSetter]("core", "tasks")
@stephenafamo
Copy link
Owner

If you have only one schema, it is not included because it assumes that the schema would be included in the search path and the queries would be slightly less verbose.

If you want to force the addition of the schema name, set the shared_schema to another value. see configuration

@rkrishnasanka
Copy link
Author

Got it working @stephenafamo ! I don't think you should put the default value for shared_schema to pick the first schema from schemas.

  1. Its a non-obvious config problem that is very hard to diagnose when running the queries, half the time I wasn't sure if I configured something wrong or if my migration screwed something up.
  2. Without the standard configuration example (full) its really hard to pinpoint this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants