Skip to content
TypeScript
6.4 KB
Raw Blame
[
  {
    "id": "schema.public",
    "label": "Create schema \"public\"",
    "operationClass": "additive",
    "target": {
      "id": "postgres"
    },
    "precheck": [],
    "execute": [
      {
        "description": "Create schema \"public\"",
        "sql": "CREATE SCHEMA IF NOT EXISTS \"public\"",
        "params": []
      }
    ],
    "postcheck": []
  },
  {
    "id": "table.post",
    "label": "Create table \"post\"",
    "summary": "Creates table \"post\"",
    "operationClass": "additive",
    "target": {
      "id": "postgres",
      "details": {
        "schema": "public",
        "objectType": "table",
        "name": "post"
      }
    },
    "precheck": [
      {
        "description": "ensure table \"post\" does not exist",
        "sql": "SELECT (to_regclass($1)) IS NULL AS \"result\"",
        "params": ["\"public\".\"post\""]
      }
    ],
    "execute": [
      {
        "description": "create table \"post\"",
        "sql": "CREATE TABLE \"public\".\"post\" (\n  \"authorId\" uuid NOT NULL,\n  \"id\" uuid NOT NULL,\n  \"title\" text NOT NULL,\n  PRIMARY KEY (\"id\")\n)",
        "params": []
      }
    ],
    "postcheck": [
      {
        "description": "verify table \"post\" exists",
        "sql": "SELECT (to_regclass($1)) IS NOT NULL AS \"result\"",
        "params": ["\"public\".\"post\""]
      }
    ]
  },
  {
    "id": "table.user",
    "label": "Create table \"user\"",
    "summary": "Creates table \"user\"",
    "operationClass": "additive",
    "target": {
      "id": "postgres",
      "details": {
        "schema": "public",
        "objectType": "table",
        "name": "user"
      }
    },
    "precheck": [
      {
        "description": "ensure table \"user\" does not exist",
        "sql": "SELECT (to_regclass($1)) IS NULL AS \"result\"",
        "params": ["\"public\".\"user\""]
      }
    ],
    "execute": [
      {
        "description": "create table \"user\"",
        "sql": "CREATE TABLE \"public\".\"user\" (\n  \"createdAt\" timestamptz DEFAULT (now()) NOT NULL,\n  \"email\" text NOT NULL,\n  \"id\" uuid NOT NULL,\n  \"name\" text NOT NULL,\n  PRIMARY KEY (\"id\")\n)",
        "params": []
      }
    ],
    "postcheck": [
      {
        "description": "verify table \"user\" exists",
        "sql": "SELECT (to_regclass($1)) IS NOT NULL AS \"result\"",
        "params": ["\"public\".\"user\""]
      }
    ]
  },
  {
    "id": "unique.user.user_email_key",
    "label": "Add unique constraint on \"user\" (email)",
    "operationClass": "additive",
    "target": {
      "id": "postgres",
      "details": {
        "schema": "public",
        "objectType": "unique",
        "name": "user_email_key",
        "table": "user"
      }
    },
    "precheck": [
      {
        "description": "ensure constraint \"user_email_key\" does not exist",
        "sql": "SELECT NOT EXISTS (SELECT 1 AS \"one\" FROM \"pg_constraint\" AS \"c\" INNER JOIN \"pg_namespace\" AS \"n\" ON \"n\".\"oid\" = \"c\".\"connamespace\" WHERE (\"c\".\"conname\" = $1 AND \"n\".\"nspname\" = $2 AND \"c\".\"conrelid\" = to_regclass($3))) AS \"result\"",
        "params": ["user_email_key", "public", "\"public\".\"user\""]
      }
    ],
    "execute": [
      {
        "description": "add unique constraint \"user_email_key\"",
        "sql": "ALTER TABLE \"public\".\"user\" ADD CONSTRAINT \"user_email_key\" UNIQUE (\"email\")"
      }
    ],
    "postcheck": [
      {
        "description": "verify constraint \"user_email_key\" exists",
        "sql": "SELECT EXISTS (SELECT 1 AS \"one\" FROM \"pg_constraint\" AS \"c\" INNER JOIN \"pg_namespace\" AS \"n\" ON \"n\".\"oid\" = \"c\".\"connamespace\" WHERE (\"c\".\"conname\" = $1 AND \"n\".\"nspname\" = $2 AND \"c\".\"conrelid\" = to_regclass($3))) AS \"result\"",
        "params": ["user_email_key", "public", "\"public\".\"user\""]
      }
    ]
  },
  {
    "id": "index.post.post_authorId_idx_e47547ed",
    "label": "Create index \"post_authorId_idx_e47547ed\" on \"post\"",
    "operationClass": "additive",
    "target": {
      "id": "postgres",
      "details": {
        "schema": "public",
        "objectType": "index",
        "name": "post_authorId_idx_e47547ed",
        "table": "post"
      }
    },
    "precheck": [
      {
        "description": "ensure index \"post_authorId_idx_e47547ed\" does not exist",
        "sql": "SELECT (to_regclass($1)) IS NULL AS \"result\"",
        "params": ["\"public\".\"post_authorId_idx_e47547ed\""]
      }
    ],
    "execute": [
      {
        "description": "create index \"post_authorId_idx_e47547ed\"",
        "sql": "CREATE INDEX \"post_authorId_idx_e47547ed\" ON \"public\".\"post\" (\"authorId\")",
        "params": []
      }
    ],
    "postcheck": [
      {
        "description": "verify index \"post_authorId_idx_e47547ed\" exists",
        "sql": "SELECT (to_regclass($1)) IS NOT NULL AS \"result\"",
        "params": ["\"public\".\"post_authorId_idx_e47547ed\""]
      }
    ]
  },
  {
    "id": "foreignKey.post.post_authorId_fkey",
    "label": "Add foreign key \"post_authorId_fkey\" on \"post\"",
    "operationClass": "additive",
    "target": {
      "id": "postgres",
      "details": {
        "schema": "public",
        "objectType": "foreignKey",
        "name": "post_authorId_fkey",
        "table": "post"
      }
    },
    "precheck": [
      {
        "description": "ensure FK \"post_authorId_fkey\" does not exist",
        "sql": "SELECT NOT EXISTS (SELECT 1 AS \"one\" FROM \"pg_constraint\" AS \"c\" INNER JOIN \"pg_namespace\" AS \"n\" ON \"n\".\"oid\" = \"c\".\"connamespace\" WHERE (\"c\".\"conname\" = $1 AND \"n\".\"nspname\" = $2 AND \"c\".\"conrelid\" = to_regclass($3))) AS \"result\"",
        "params": ["post_authorId_fkey", "public", "\"public\".\"post\""]
      }
    ],
    "execute": [
      {
        "description": "add FK \"post_authorId_fkey\"",
        "sql": "ALTER TABLE \"public\".\"post\"\nADD CONSTRAINT \"post_authorId_fkey\"\nFOREIGN KEY (\"authorId\")\nREFERENCES \"public\".\"user\" (\"id\")"
      }
    ],
    "postcheck": [
      {
        "description": "verify FK \"post_authorId_fkey\" exists",
        "sql": "SELECT EXISTS (SELECT 1 AS \"one\" FROM \"pg_constraint\" AS \"c\" INNER JOIN \"pg_namespace\" AS \"n\" ON \"n\".\"oid\" = \"c\".\"connamespace\" WHERE (\"c\".\"conname\" = $1 AND \"n\".\"nspname\" = $2 AND \"c\".\"conrelid\" = to_regclass($3))) AS \"result\"",
        "params": ["post_authorId_fkey", "public", "\"public\".\"post\""]
      }
    ]
  }
]