From db64238c1c73fc7cb3bc615a615277991e42832a Mon Sep 17 00:00:00 2001 From: Eric Cabrel TIOGO Date: Sun, 1 Sep 2024 23:41:45 +0200 Subject: [PATCH] fix: migration diff step n tests --- .github/workflows/migration-db-check.yml | 5 --- README.md | 4 +-- apps/backend/README.md | 4 +-- apps/backend/src/utils/tests/helpers.ts | 2 ++ packages/domain/README.md | 44 +++++------------------- packages/domain/migration-message.txt | 0 6 files changed, 14 insertions(+), 45 deletions(-) delete mode 100644 packages/domain/migration-message.txt diff --git a/.github/workflows/migration-db-check.yml b/.github/workflows/migration-db-check.yml index 85957468..501b8b03 100644 --- a/.github/workflows/migration-db-check.yml +++ b/.github/workflows/migration-db-check.yml @@ -49,11 +49,6 @@ jobs: echo "" >> migration-message.txt echo "Please ensure your schema changes are compatible with the application code currently running in production." >> migration-message.txt -# - name: Comment pull request with the migration diff -# uses: thollander/actions-comment-pull-request@v2 -# with: -# filePath: packages/domain/migration-message.txt - - name: Create or update the pull request with the migration diff uses: actions/github-script@v6 id: plan-comment diff --git a/README.md b/README.md index e8f2b7b1..9d2fcada 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Snipcode is an open-source code-sharing platform that makes it easy to create co * [Node.js](https://nodejs.org/en/) * [TypeScript](https://www.typescriptlang.org/) * [GraphQL](https://graphql.org/) -* [MySQL 8 with PlanetScale](https://planetscale.com/) +* [MySQL 8.0](https://dev.mysql.com/doc/refman/8.0/en/) * [Prisma](https://www.prisma.io/) * [Tailwind CSS](https://tailwindcss.com/) * [AWS](https://aws.amazon.com) @@ -29,11 +29,9 @@ snipcode │ ├─ backend │ ├─ web ├─ packages -│ ├─ database │ ├─ embed │ ├─ domain │ ├─ front -│ ├─ logger │ ├─ utils package.json tsconfig.base.json diff --git a/apps/backend/README.md b/apps/backend/README.md index be03994b..5372fc9a 100644 --- a/apps/backend/README.md +++ b/apps/backend/README.md @@ -1,4 +1,4 @@ -# Snipcode Core +# Snipcode Backend This is the backend of Snipcode, containing the business logics related to . @@ -15,7 +15,7 @@ Make sure you have these tools installed before running the project * NPM or Yarn * Docker * AWS CLI v2 -* MySQL 8 on PlanetScale +* MySQL 8.0 ## Packages dependencies We use Yarn workspace to create packages we can share with other applications. diff --git a/apps/backend/src/utils/tests/helpers.ts b/apps/backend/src/utils/tests/helpers.ts index ad825962..ca845f0a 100644 --- a/apps/backend/src/utils/tests/helpers.ts +++ b/apps/backend/src/utils/tests/helpers.ts @@ -47,7 +47,9 @@ export class TestHelper { await prismaService.snippet.deleteMany(); // Recursive relationship between folders makes it hard to delete all folders using folder.deleteMany() + await prismaService.$executeRaw`SET FOREIGN_KEY_CHECKS=0;`; await prismaService.$executeRaw`TRUNCATE TABLE folders;`; + await prismaService.$executeRaw`SET FOREIGN_KEY_CHECKS=1;`; await prismaService.session.deleteMany(); diff --git a/packages/domain/README.md b/packages/domain/README.md index d574784c..d7cebb27 100644 --- a/packages/domain/README.md +++ b/packages/domain/README.md @@ -11,7 +11,6 @@ Make sure you have this tools installed before running the project * Node.js 20+ * Yarn 4 * Docker -* [The PlanetScale CLI](https://planetscale.com/cli) ## Set up the project Delete the existing folders output from build commands @@ -29,42 +28,23 @@ Create the .env file from the template. This file is useful for test executions, cp .env.template .env ``` -Create git branch for your feature; there is no convention for the branch name. +### Start the local database and run the migrations ```shell -git checkout -b your-feature-name -``` - -### Connect to the local database locally -This project uses PlanetScale as the database.
-To connect to the database locally, you must authenticate first (Ask the credentials to [@tericcabrel](https://github.com/tericcabrel)).
-Once authenticated from the terminal, execute the commands below to create a database branch for your feature and create local tunnel to it. -```shell -yarn db:branch:dev -yarn db:branch:connect -``` -Open a second terminal and run the command below to start the shadow database; -this is only necessary to run generate or execute database migrations with prisma schema -```shell -yarn db:shadow +yarn db:local +yarn db:migrate ``` -The shadow database runs on Docker, you can stop it when you don't need it +### Generate Prisma types and seed the database with default data ```shell -yarn db:shadow:stop +yarn db:generate +yarn db:seed ``` -### Connect to the development database -The development database is used to beta test features. Execute the command below to connect to it +To stop the local database run the command below: ```shell -yarn db:dev:connect +yarn db:local:stop ``` -### Run the database migration, generate Prisma types and seed the database with default data -```shell -yarn db:generate -yarn db:migrate -yarn db:seed -``` ### Generate a database migration To create a database migration that generate the SQL file, run the command below: @@ -78,13 +58,7 @@ yarn db:migrate --name - Open Prisma Studio to browse your database: `db:view` - Lint the Prisma schema file: `db:format` -### Create a deployment request -To publish the database schema changes in production, you must create a deployment request. Run the command below to do that -```shell -yarn db:deploy:create -``` - -Build the package to generate types declaration required to provide autocompletion while using the functions in the core or Lambda functions +Build the package to generate types declaration required to provide autocompletion while using the functions in the backend application ```bash yarn build ``` diff --git a/packages/domain/migration-message.txt b/packages/domain/migration-message.txt deleted file mode 100644 index e69de29b..00000000