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

atlas schema apply: complains that auto-generated dev schema does not exist #1711

Closed
silasdavis opened this issue Jun 1, 2023 · 3 comments · Fixed by #1768
Closed

atlas schema apply: complains that auto-generated dev schema does not exist #1711

silasdavis opened this issue Jun 1, 2023 · 3 comments · Fixed by #1768

Comments

@silasdavis
Copy link
Contributor

When running (on v0.12.0 / postgres):

❯ atlas schema apply --env local

I get the following error:

-- Planned Changes:
-- Create "Queue" table
CREATE TABLE "beehive"."Queue" ("slotId" integer NOT NULL DEFAULT nextval('atlas_dev_beehive_1685639082."Queue_slotId_seq"'::regclass), "status" "beehive"."QueueStatus" NOT NULL DEFAULT 'ACCEPTED', "request" jsonb NOT NULL, "result" jsonb NULL, "error" text NULL, "enqueueTime" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updateTime" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "routingTag" text NOT NULL, "requestId" text NOT NULL, PRIMARY KEY ("slotId"));
-- Create index "Queue_routingTag_requestId_key" to table: "Queue"
CREATE UNIQUE INDEX "Queue_routingTag_requestId_key" ON "beehive"."Queue" ("routingTag", "requestId");
-- Create "RoyaltyData" table
CREATE TABLE "beehive"."RoyaltyData" ("collectionContract" text NOT NULL, "executingContract" text NOT NULL, "tokenContract" text NOT NULL, "blockNumber" integer NOT NULL, "transactionHash" text NOT NULL, "logIndex" integer NOT NULL, "fromAddr" text NOT NULL, "toAddr" text NOT NULL, "tokenId" text NOT NULL, "data" text NOT NULL, "amount" bigint NOT NULL, "timestamp" timestamp(3) NOT NULL, PRIMARY KEY ("transactionHash", "logIndex"));
✔ Apply
Error: create "Queue" table: pq: schema "atlas_dev_beehive_1685639082" does not exist

With atlas.hcl:

variable "POSTGRES_DB" {
  type = string
  default = "pmp_dev"
}
variable "POSTGRES_USER" {
  type = string
  default = "postgres"
}
variable "POSTGRES_PASSWORD" {
  type = string
  default = "postgres"
}
variable "POSTGRES_SCHEMA" {
  type = string
  default = "beehive"
}
// Define an environment named "local"
env "local" {
  // Declare where the schema definition resides.
  // Also supported:
  //   src = "./dir/with/schema"
  //   src = ["multi.hcl", "file.hcl"]
  src = "./schema.hcl"

  // Define the URL of the database which is managed in
  // this environment.
  url = "postgres://${var.POSTGRES_USER}:${var.POSTGRES_PASSWORD}@0.0.0.0:5432/${var.POSTGRES_DB}?sslmode=disable"

  // Define the URL of the Dev Database for this environment
  // See: https://atlasgo.io/concepts/dev-database
  dev = "postgres://${var.POSTGRES_USER}:${var.POSTGRES_PASSWORD}@0.0.0.0:5432/atlas_dev?sslmode=disable"

  // The schemas in the database that are managed by Atlas.
  schemas = ["${var.POSTGRES_SCHEMA}"]
}

and schema.hcl:

table "Extraction" {
  schema = schema.beehive
  column "extractionId" {
    null = false
    type = text
  }
  column "chainId" {
    null = false
    type = integer
  }
  column "lastBlockNumber" {
    null = false
    type = integer
  }
  column "outputsHash" {
    null = false
    type = text
  }
  primary_key {
    columns = [column.extractionId]
  }
}
table "Queue" {
  schema = schema.beehive
  column "slotId" {
    null = false
    type = serial
  }
  column "status" {
    null    = false
    type    = enum.QueueStatus
    default = "ACCEPTED"
  }
  column "request" {
    null = false
    type = jsonb
  }
  column "result" {
    null = true
    type = jsonb
  }
  column "error" {
    null = true
    type = text
  }
  column "enqueueTime" {
    null    = false
    type    = timestamp(3)
    default = sql("CURRENT_TIMESTAMP")
  }
  column "updateTime" {
    null    = false
    type    = timestamp(3)
    default = sql("CURRENT_TIMESTAMP")
  }
  column "routingTag" {
    null = false
    type = text
  }
  column "requestId" {
    null = false
    type = text
  }
  primary_key {
    columns = [column.slotId]
  }
  index "Queue_routingTag_requestId_key" {
    unique  = true
    columns = [column.routingTag, column.requestId]
  }
}
table "RoyaltyData" {
  schema = schema.beehive
  column "collectionContract" {
    null = false
    type = text
  }
  column "executingContract" {
    null = false
    type = text
  }
  column "tokenContract" {
    null = false
    type = text
  }
  column "blockNumber" {
    null = false
    type = integer
  }
  column "transactionHash" {
    null = false
    type = text
  }
  column "logIndex" {
    null = false
    type = integer
  }
  column "fromAddr" {
    null = false
    type = text
  }
  column "toAddr" {
    null = false
    type = text
  }
  column "tokenId" {
    null = false
    type = text
  }
  column "data" {
    null = false
    type = text
  }
  column "amount" {
    null = false
    type = bigint
  }
  column "timestamp" {
    null = false
    type = timestamp(3)
  }
  primary_key {
    columns = [column.transactionHash, column.logIndex]
  }
}
enum "QueueStatus" {
  schema = schema.beehive
  values = ["ACCEPTED", "EXECUTING", "COMPLETED", "ERRORED"]
}
schema "beehive" {
}
@silasdavis
Copy link
Contributor Author

@a8m sniffed this: nextval('atlas_dev_beehive_1685639082."Queue_slotId_seq"'::regclass) as being suscipicious via discord

@silasdavis
Copy link
Contributor Author

silasdavis commented Jun 16, 2023

I upgraded to this git revision to catch some fixes: 661ade00ec500ddcaf07be5b7cb1fd2092317f4d

My latest config is:

atlas.hcl:

variable "POSTGRES_DB" {
  type    = string
  default = getenv("POSTGRES_DB")
}
variable "POSTGRES_USER" {
  type    = string
  default = getenv("POSTGRES_USER")
}
variable "POSTGRES_PASSWORD" {
  type    = string
  default = getenv("POSTGRES_PASSWORD")
}

variable "POSTGRES_SCHEMA" {
  type    = string
  default = "beehive"
}

variable "POSTGRES_SSL_MODE" {
  type    = string
  default = getenv("POSTGRES_SSL_MODE") != "" ? getenv("POSTGRES_SSL_MODE") : "disable"
}

env {
  // This is required, and is taken from the --env flag passed to the CLI. In an an unlabelled block like this its only
  // used in the Atlas UI to show deployments.
  name = atlas.env
  // Declare where the schema definition resides.
  // Also supported:
  //   src = "./dir/with/schema"
  //   src = ["multi.hcl", "file.hcl"]
#  src = "./schema.sql"
  src = "./schema.hcl"

  // Define the URL of the database which is managed in
  // this environment.
  url = "postgres://${var.POSTGRES_USER}:${var.POSTGRES_PASSWORD}@0.0.0.0:5432/${var.POSTGRES_DB}?sslmode=${var.POSTGRES_SSL_MODE}"

  // Define the URL of the Dev Database for this environment
  // See: https://atlasgo.io/concepts/dev-database
  dev = "docker://postgres/15/dev"

  migration {
    // URL where the migration directory resides. Only filesystem directories
    // are currently supported but more options will be added in the future.
    dir = "file://migrations"
    // An optional format of the migration directory:
    // atlas (default) | flyway | liquibase | goose | golang-migrate | dbmate
    format = atlas
  }
}

schema.hcl:

schema "beehive" {
}
table "Extraction" {
  schema = schema.beehive
  column "extractionId" {
    null = false
    type = text
  }
  column "chainId" {
    null = false
    type = integer
  }
  column "lastBlockNumber" {
    null = false
    type = integer
  }
  column "outputsHash" {
    null = false
    type = text
  }
  primary_key {
    columns = [column.extractionId]
  }
}
table "Queue" {
  schema = schema.beehive
  column "slotId" {
    null    = false
    type    = integer
    default = sql("nextval('beehive.\"Queue_slotId_seq\"'::regclass)")
  }
  column "status" {
    null    = false
    type    = enum.QueueStatus
    default = "ACCEPTED"
  }
  column "request" {
    null = false
    type = jsonb
  }
  column "result" {
    null = true
    type = jsonb
  }
  column "error" {
    null = true
    type = text
  }
  column "enqueueTime" {
    null    = false
    type    = timestamp(3)
    default = sql("CURRENT_TIMESTAMP")
  }
  column "updateTime" {
    null    = false
    type    = timestamp(3)
    default = sql("CURRENT_TIMESTAMP")
  }
  column "routingTag" {
    null = false
    type = text
  }
  column "requestId" {
    null = false
    type = text
  }
  primary_key {
    columns = [column.slotId]
  }
  index "Queue_routingTag_requestId_key" {
    unique  = true
    columns = [column.routingTag, column.requestId]
  }
}
table "atlas_schema_revisions" {
  schema = schema.beehive
  column "version" {
    null = false
    type = character_varying
  }
  column "description" {
    null = false
    type = character_varying
  }
  column "type" {
    null    = false
    type    = bigint
    default = 2
  }
  column "applied" {
    null    = false
    type    = bigint
    default = 0
  }
  column "total" {
    null    = false
    type    = bigint
    default = 0
  }
  column "executed_at" {
    null = false
    type = timestamptz
  }
  column "execution_time" {
    null = false
    type = bigint
  }
  column "error" {
    null = true
    type = text
  }
  column "error_stmt" {
    null = true
    type = text
  }
  column "hash" {
    null = false
    type = character_varying
  }
  column "partial_hashes" {
    null = true
    type = jsonb
  }
  column "operator_version" {
    null = false
    type = character_varying
  }
  primary_key {
    columns = [column.version]
  }
}
enum "QueueStatus" {
  schema = schema.beehive
  values = ["ACCEPTED", "EXECUTING", "COMPLETED", "ERRORED"]
}

Gives error:

❯ atlas migrate diff --env local my_baseline
Error: create "Queue" table: pq: schema "beehive" does not exist

My schema has beehive defined so I hoped it would create it...

If I create beehive, then I get the exact same error anyway.

@silasdavis
Copy link
Contributor Author

this is running with a DB with some other schemas in it.

I get the same error with or without schemas = ["beehive"]

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

Successfully merging a pull request may close this issue.

1 participant