From b57eb06290a330da1138a7155eb11f95ba1afe93 Mon Sep 17 00:00:00 2001 From: CJ Brewer Date: Mon, 16 Sep 2024 12:52:58 -0600 Subject: [PATCH] feat(postgres): init prisma example --- .gitignore | 179 +++++++++++++++- postgres/db/Dockerfile | 9 + postgres/examples/prisma/.env.example | 1 + postgres/examples/prisma/README.md | 46 ++++ postgres/examples/prisma/bun.lockb | Bin 0 -> 6372 bytes postgres/examples/prisma/index.ts | 15 ++ postgres/examples/prisma/package.json | 15 ++ .../20240913124049_init/migration.sql | 202 ++++++++++++++++++ .../prisma/migrations/migration_lock.toml | 3 + postgres/examples/prisma/prisma/schema.prisma | 137 ++++++++++++ postgres/examples/prisma/tsconfig.json | 27 +++ 11 files changed, 632 insertions(+), 2 deletions(-) create mode 100644 postgres/examples/prisma/.env.example create mode 100644 postgres/examples/prisma/README.md create mode 100755 postgres/examples/prisma/bun.lockb create mode 100644 postgres/examples/prisma/index.ts create mode 100644 postgres/examples/prisma/package.json create mode 100644 postgres/examples/prisma/prisma/migrations/20240913124049_init/migration.sql create mode 100644 postgres/examples/prisma/prisma/migrations/migration_lock.toml create mode 100644 postgres/examples/prisma/prisma/schema.prisma create mode 100644 postgres/examples/prisma/tsconfig.json diff --git a/.gitignore b/.gitignore index e25ff9f..024fdcc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,184 @@ cipherstash-proxy.custom.toml -.DS_Store # Temporary until this is better implemented k8s .envrc -dynamodb/app/target \ No newline at end of file +dynamodb/app/target + +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/postgres/db/Dockerfile b/postgres/db/Dockerfile index fc07a56..77d176c 100644 --- a/postgres/db/Dockerfile +++ b/postgres/db/Dockerfile @@ -1,4 +1,13 @@ FROM --platform=linux/amd64 postgres:16 as db + +# Install pgvector +RUN apt-get update && apt-get install -y git make build-essential +RUN apt-get install -y postgresql-server-dev-16 +RUN git clone --branch v0.7.4 https://github.com/pgvector/pgvector.git +WORKDIR /pgvector +RUN make +RUN make install + WORKDIR /app COPY init.sh /docker-entrypoint-initdb.d COPY dump.sql ./scripts/db/dump.sql diff --git a/postgres/examples/prisma/.env.example b/postgres/examples/prisma/.env.example new file mode 100644 index 0000000..1306b20 --- /dev/null +++ b/postgres/examples/prisma/.env.example @@ -0,0 +1 @@ +DATABASE_URL=postgres://postgres:password@localhost:5432/postgres \ No newline at end of file diff --git a/postgres/examples/prisma/README.md b/postgres/examples/prisma/README.md new file mode 100644 index 0000000..acd0538 --- /dev/null +++ b/postgres/examples/prisma/README.md @@ -0,0 +1,46 @@ +# cipherstash-prisma-orm-example + +To install dependencies: + +```bash +bun install +``` + +## Environment variables + +Copy the `.env.example` file to the two additional files: + +- `.env.local` - Used for the application `index.ts` file and connects through CipherStash Proxy +- `.env` - Used for the Prisma Migrations + +Edit the `.env.local` file to include the following environment variables: + +```bash +DATABASE_URL=postgres://postgres:password@localhost:6432/postgres +``` + +Edit the `.env` file to include the following environment variables: + +```bash +DATABASE_URL=postgres://postgres:password@localhost:5432/postgres +``` + +The only difference is the port number. + +## Running migrations + +To run migrations run the following command: + +```bash +bun prisma migrate dev +``` + +This will run the migrations against the local database. + +## Running the application + +Run the following command to start the application: + +```bash +bun run index.ts +``` diff --git a/postgres/examples/prisma/bun.lockb b/postgres/examples/prisma/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..7ae99b8f643faccea974c211c9da8fc917b4d58a GIT binary patch literal 6372 zcmeHL2~-nV7Og;V!4^?b+zE=JNLCUEh=8KqdSGlt$6-{ItrEhLKq^7Og=mAK1I?n) zhzl-YE2yKbh=ZaijXEmsThmIbw4!#8j*gjxpq)V5fbI;sE9l-#TLS&8pgkP4C1{m7L39Sa4|EsM z&7eO4y@R7smPvs>PL|#x83^h29Od&(T?T->P3rHrxC4+HUfbI#Gsk|7U z4H!A#Q5!--U!dM87=IFadVhrdUEpwHJNTt=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