Skip to content

Extensions not created before tables #3602

@miguelvr

Description

@miguelvr

Running the exact same example documented in https://atlasgo.io/faq/postgres-extensions yields an error from atlas, when using atlas-operator:

  1. Apply this schema:
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasSchema
metadata:
  name: postgres-postgresql-schema
spec:
  credentials:
    scheme: postgres
    host: postgres-postgresql.default
    user: postgres
    database: postgres
    port: 5432
    parameters:
      sslmode: disable
    passwordFrom:
      secretKeyRef:
        key: postgres-password
        name: postgres-postgresql
  schema:
    sql: |
      CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
      
      CREATE SCHEMA IF NOT EXISTS "public";
      
      -- Table to store customers, qualified with schema name
      CREATE TABLE public.customers (
          id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
          first_name VARCHAR(100) NOT NULL,
          last_name VARCHAR(100) NOT NULL,
          email VARCHAR(255) UNIQUE NOT NULL
      );
      
      -- Table to store products, qualified with schema name
      CREATE TABLE public.products (
          id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
          name VARCHAR(255) NOT NULL,
          description TEXT,
          price DECIMAL(10, 2) NOT NULL
      );
      
      -- Table to store orders, qualified with schema name
      CREATE TABLE public.orders (
          id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
          customer_id UUID REFERENCES customers(id) ON DELETE CASCADE,
          order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
          status VARCHAR(50) DEFAULT 'Pending'
      );
  1. Error message:
Error: analyzing plan: running first analysis: executing statement: CREATE TABLE "public"."customers" (
  "id" uuid NOT NULL DEFAULT public.uuid_generate_v4(),
  "first_name" character varying(100) NOT NULL,
  "last_name" character varying(100) NOT NULL,
  "email" character varying(255) NOT NULL,
  PRIMARY KEY ("id"),
  CONSTRAINT "customers_email_key" UNIQUE ("email")
);: pq: function public.uuid_generate_v4() does not exist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions