Skip to content

Commit

Permalink
feat: pg schema + orm setup with drizzle
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrsoares committed Aug 7, 2023
1 parent 617f45d commit eb35b22
Show file tree
Hide file tree
Showing 11 changed files with 1,223 additions and 4 deletions.
13 changes: 13 additions & 0 deletions apps/maestro/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as dotenv from "dotenv";
import type { Config } from "drizzle-kit";

dotenv.config({ path: ".env.local" });

export default {
schema: "./src/lib/drizzle/schema",
out: "./src/lib/drizzle/client",
driver: "pg",
dbCredentials: {
connectionString: `${process.env.POSTGRES_URL}?sslmode=require`,
},
} satisfies Config;
5 changes: 5 additions & 0 deletions apps/maestro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"@vercel/kv": "^0.2.2",
"@vercel/postgres": "^0.4.1",
"@web3modal/ethereum": "^2.7.1",
"@web3modal/react": "^2.7.1",
"clsx": "^1.2.1",
"drizzle-orm": "^0.28.0",
"eslint": "^8.46.0",
"eslint-config-next": "13.4.9",
"ky": "^0.33.3",
Expand All @@ -52,6 +54,7 @@
"next": "13.4.9",
"nextjs-cors": "^2.1.2",
"nprogress": "^0.2.0",
"pg": "^8.11.2",
"rambda": "^7.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -88,6 +91,8 @@
"concurrently": "^8.2.0",
"dotenv": "^16.3.1",
"dotenv-cli": "^7.2.1",
"drizzle-kit": "^0.19.12",
"drizzle-zod": "^0.5.0",
"happy-dom": "^9.20.3",
"matchers": "link:@testing-library/jest-dom/matchers",
"next-auth": "^4.22.4",
Expand Down
40 changes: 40 additions & 0 deletions apps/maestro/src/lib/drizzle/client/0000_narrow_inertia.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
DO $$ BEGIN
CREATE TYPE "kind" AS ENUM('canonical', 'standardized');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "status" AS ENUM('deployed', 'pending');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "interchain_tokens" (
"token_id" varchar(64) PRIMARY KEY NOT NULL,
"token_address" varchar(40),
"token_name" text,
"token_symbol" text,
"token_decimals" integer,
"chain_id" integer,
"axelar_chain_id" varchar(48),
"deployment_tx_hash" varchar(64),
"deployer_address" varchar(40) NOT NULL,
"kind" "kind" NOT NULL,
"salt" varchar(64),
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "remote_interchain_tokens" (
"token_id" varchar(64) PRIMARY KEY NOT NULL,
"origin_token_id" varchar(64),
"chain_id" integer,
"axelar_chain_id" varchar,
"address" varchar(40),
"status" "status",
"deployment_tx_hash" varchar(64),
"deployment_log_index" integer,
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL
);
21 changes: 21 additions & 0 deletions apps/maestro/src/lib/drizzle/client/0001_ordinary_blob.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_id" SET DATA TYPE varchar(66);--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_address" SET DATA TYPE varchar(42);--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_address" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_name" SET DATA TYPE varchar(100);--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_name" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_symbol" SET DATA TYPE varchar(100);--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_symbol" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_decimals" SET DATA TYPE smallint;--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "token_decimals" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "chain_id" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "axelar_chain_id" SET DATA TYPE varchar(66);--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "axelar_chain_id" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "deployment_tx_hash" SET DATA TYPE varchar(66);--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "deployer_address" SET DATA TYPE varchar(42);--> statement-breakpoint
ALTER TABLE "interchain_tokens" ALTER COLUMN "salt" SET DATA TYPE varchar(66);--> statement-breakpoint
ALTER TABLE "remote_interchain_tokens" ALTER COLUMN "token_id" SET DATA TYPE varchar(66);--> statement-breakpoint
ALTER TABLE "remote_interchain_tokens" ALTER COLUMN "origin_token_id" SET DATA TYPE varchar(66);--> statement-breakpoint
ALTER TABLE "remote_interchain_tokens" ALTER COLUMN "address" SET DATA TYPE varchar(42);--> statement-breakpoint
ALTER TABLE "remote_interchain_tokens" ALTER COLUMN "deployment_tx_hash" SET DATA TYPE varchar(66);--> statement-breakpoint
ALTER TABLE "remote_interchain_tokens" ADD COLUMN "deployment_status" "status";--> statement-breakpoint
ALTER TABLE "remote_interchain_tokens" DROP COLUMN IF EXISTS "status";
188 changes: 188 additions & 0 deletions apps/maestro/src/lib/drizzle/client/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{
"version": "5",
"dialect": "pg",
"id": "585ea645-1fde-4995-bd80-8add01cec875",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"interchain_tokens": {
"name": "interchain_tokens",
"schema": "",
"columns": {
"token_id": {
"name": "token_id",
"type": "varchar(64)",
"primaryKey": true,
"notNull": true
},
"token_address": {
"name": "token_address",
"type": "varchar(40)",
"primaryKey": false,
"notNull": false
},
"token_name": {
"name": "token_name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"token_symbol": {
"name": "token_symbol",
"type": "text",
"primaryKey": false,
"notNull": false
},
"token_decimals": {
"name": "token_decimals",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"chain_id": {
"name": "chain_id",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"axelar_chain_id": {
"name": "axelar_chain_id",
"type": "varchar(48)",
"primaryKey": false,
"notNull": false
},
"deployment_tx_hash": {
"name": "deployment_tx_hash",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"deployer_address": {
"name": "deployer_address",
"type": "varchar(40)",
"primaryKey": false,
"notNull": true
},
"kind": {
"name": "kind",
"type": "kind",
"primaryKey": false,
"notNull": true
},
"salt": {
"name": "salt",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"remote_interchain_tokens": {
"name": "remote_interchain_tokens",
"schema": "",
"columns": {
"token_id": {
"name": "token_id",
"type": "varchar(64)",
"primaryKey": true,
"notNull": true
},
"origin_token_id": {
"name": "origin_token_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"chain_id": {
"name": "chain_id",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"axelar_chain_id": {
"name": "axelar_chain_id",
"type": "varchar",
"primaryKey": false,
"notNull": false
},
"address": {
"name": "address",
"type": "varchar(40)",
"primaryKey": false,
"notNull": false
},
"status": {
"name": "status",
"type": "status",
"primaryKey": false,
"notNull": false
},
"deployment_tx_hash": {
"name": "deployment_tx_hash",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"deployment_log_index": {
"name": "deployment_log_index",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {
"kind": {
"name": "kind",
"values": {
"canonical": "canonical",
"standardized": "standardized"
}
},
"status": {
"name": "status",
"values": {
"deployed": "deployed",
"pending": "pending"
}
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
Loading

0 comments on commit eb35b22

Please sign in to comment.