From 35c18c743d9e169d43ebb61b461c0372caeeedf2 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 11 Dec 2023 10:37:45 +0100 Subject: [PATCH 1/4] database as sqlite --- prisma/migrations/20231206124213_test/migration.sql | 8 -------- .../20231211091701_initial_migration/migration.sql | 6 ++++++ prisma/migrations/migration_lock.toml | 2 +- prisma/schema.prisma | 6 ++++-- 4 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 prisma/migrations/20231206124213_test/migration.sql create mode 100644 prisma/migrations/20231211091701_initial_migration/migration.sql diff --git a/prisma/migrations/20231206124213_test/migration.sql b/prisma/migrations/20231206124213_test/migration.sql deleted file mode 100644 index 18d180d..0000000 --- a/prisma/migrations/20231206124213_test/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- CreateTable -CREATE TABLE `Hello` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `text` VARCHAR(191) NOT NULL, - `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; diff --git a/prisma/migrations/20231211091701_initial_migration/migration.sql b/prisma/migrations/20231211091701_initial_migration/migration.sql new file mode 100644 index 0000000..438ad14 --- /dev/null +++ b/prisma/migrations/20231211091701_initial_migration/migration.sql @@ -0,0 +1,6 @@ +-- CreateTable +CREATE TABLE "Hello" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "text" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml index e5a788a..e5e5c47 100644 --- a/prisma/migrations/migration_lock.toml +++ b/prisma/migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually # It should be added in your version-control system (i.e. Git) -provider = "mysql" \ No newline at end of file +provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 68a135c..a68cbc1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -3,8 +3,10 @@ generator client { } datasource db { - provider = "mysql" - url = env("DATABASE_URL") + provider = "sqlite" + url = "file:./development.db" + // provider = "mysql" + // url = env("DATABASE_URL") } model Hello { From de06aadf9634159ca55c540a0cdf64ce650d561c Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 11 Dec 2023 10:37:52 +0100 Subject: [PATCH 2/4] update readme.md --- README.md | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 95f36f6..3e2c967 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@ [![nodejs][badge-nodejs-img]][badge-nodejs-href] [![npm][badge-npm-img]][badge-npm-href] [![docker][badge-docker-img]][badge-docker-href] -[![eslint][badge-eslint-img]][badge-eslint-href] [![apollo-server][badge-apollo-img]][badge-apollo-href] [![graphql][badge-graphql-img]][badge-graphql-href] [![type-graphql][badge-type-graphql-img]][badge-type-graphql-href] [![prisma][badge-prisma-img]][badge-prisma-href] +[![eslint][badge-eslint-img]][badge-eslint-href] +[![remark-cli][badge-remark-cli-img]][badge-remark-cli-href] +[![jest][badge-jest-img]][badge-jest-href] [![vuepress][badge-vuepress-img]][badge-vuepress-href] The IT4C Boilerplate for an apollo express backends. @@ -17,10 +19,6 @@ To be able to build this project you need `nodejs`, `npm` and optional `docker`. The project sets up an apollo server. It uses `type-graphql`. -The project is set up for a `mysql` database, which is expected to -run. Copy the `.env.dist` file to `.env`. You can change the database -connection in the `prisma/schema.prisma` file and your local `.env`. - ## Commands The following commands are available: @@ -78,6 +76,12 @@ The following endpoints are provided given the right command is executed or all | [http://localhost:4000/graphql](http://localhost:4000/graphql) | GraphQL API | | [http://localhost:4000/playground](http://localhost:4000/playground) | GraphQL Playground | +## Database setup + +The project is set up for a `sqlite` database. +In order to run the project against a mysql database adjust `primsa/schema.prisma`, copy the `.env.dist` file to `.env` and configure the database connection appropriately. +Then run `npm run db:migrate` to generate the database. It might be required to delete the migration folder beforehand. + ## License [Apache 2.0](./LICENSE) @@ -92,20 +96,26 @@ The following endpoints are provided given the right command is executed or all [badge-docker-img]: https://img.shields.io/badge/docker-latest-blue [badge-docker-href]: https://www.docker.com/ -[badge-eslint-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=devDependencies.eslint&label=eslint&color=red -[badge-eslint-href]: https://eslint.org/ - -[badge-apollo-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=dependencies%5B%22%40apollo%2Fserver%22%5D&label=apollo-server&color=yellow +[badge-apollo-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=dependencies%5B%22%40apollo%2Fserver%22%5D&label=apollo-server&color=green [badge-apollo-href]: https://apollographql.com -[badge-graphql-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=dependencies.graphql&label=graphql&color=yellow +[badge-graphql-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=dependencies.graphql&label=graphql&color=green [badge-graphql-href]: https://graphql.org/ -[badge-type-graphql-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=dependencies%5B%22type-graphql%22%5D&label=type-graphql&color=yellow +[badge-type-graphql-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=dependencies%5B%22type-graphql%22%5D&label=type-graphql&color=green [badge-type-graphql-href]: https://typegraphql.com/ -[badge-prisma-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=dependencies.prisma&label=prisma&color=yellow +[badge-prisma-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=dependencies.prisma&label=prisma&color=green [badge-prisma-href]: https://prisma.io/ +[badge-eslint-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=devDependencies.eslint&label=eslint&color=yellow +[badge-eslint-href]: https://eslint.org/ + +[badge-remark-cli-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=devDependencies%5B%27remark-cli%27%5D&label=remark-cli&color=yellow +[badge-remark-cli-href]: https://remark.js.org/ + +[badge-jest-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=devDependencies.jest&label=jest&color=yellow +[badge-jest-href]: https://jestjs.io/ + [badge-vuepress-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-backend%2Fmaster%2Fpackage.json&query=devDependencies.vuepress&label=vuepress&color=orange [badge-vuepress-href]: https://vuepress.vuejs.org/ From b215574df8e0eb948f828bcd851fe6740c2cbacd Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 11 Dec 2023 10:40:45 +0100 Subject: [PATCH 3/4] ignore database file --- prisma/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 prisma/.gitignore diff --git a/prisma/.gitignore b/prisma/.gitignore new file mode 100644 index 0000000..5e828f2 --- /dev/null +++ b/prisma/.gitignore @@ -0,0 +1 @@ +development.db \ No newline at end of file From 637bc1c955b3574eb8bfdf5aef06e9c73bd3037b Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 11 Dec 2023 10:40:53 +0100 Subject: [PATCH 4/4] migrate database before unit tests --- .github/workflows/backend.test.unit.code.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.test.unit.code.yml b/.github/workflows/backend.test.unit.code.yml index bfabf40..229f3b6 100644 --- a/.github/workflows/backend.test.unit.code.yml +++ b/.github/workflows/backend.test.unit.code.yml @@ -31,4 +31,4 @@ jobs: uses: actions/checkout@v3 - name: Backend | Unit - run: npm install && npm run test:unit \ No newline at end of file + run: npm install && npm run db:migrate && npm run test:unit \ No newline at end of file