Skip to content

Commit

Permalink
feat: add task: prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
bingtsingw committed Aug 20, 2022
1 parent 44af4ec commit ea213c7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[mrm](https://github.com/sapegin/mrm) preset to keep configuration files in-sync and consistent across various projects. Highly inspired by [mrm-preset-default](https://github.com/sapegin/mrm/tree/master/packages/mrm-preset-default) and [@adonisjs/mrm-preset](https://github.com/adonisjs/mrm-preset).

> :white_check_mark: This project is configured by itself.
> :warning: This documentation uses [@antfu/ni](https://github.com/antfu/ni) for npm operations.
## Usage
Expand Down Expand Up @@ -90,3 +92,12 @@ $ nr mrm typescript
```bash
$ nr mrm prettier
```

### Prisma

1. Add `prisma` package and script
2. Init `prisma` and add `diff.sh`

```bash
$ nr mrm prisma
```
26 changes: 26 additions & 0 deletions prisma/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { chmodSync, existsSync } = require('fs');
const { install, packageJson, template } = require('mrm-core');
const { join } = require('path');

const task = async () => {
const { execa } = await import('execa');

install(['prisma', 'del-cli']);

packageJson()
.setScript('prisma:diff', './prisma/diff.sh')
.setScript('prisma:refresh', 'del-cli prisma/migrations && prisma migrate dev --name init --skip-generate')
.setScript('prisma:run', 'prisma migrate dev --name init --skip-generate')
.save();

if (!existsSync('prisma')) {
execa('npx prisma init');
}

const diff = 'prisma/diff.sh';
template(diff, join(__dirname, '../templates/prisma/diff.sh')).apply().save();
chmodSync(diff, 0755);
};

task.description = 'Add prisma';
module.exports = task;
7 changes: 7 additions & 0 deletions templates/prisma/diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#/bin/bash

set -o allexport
source .env set
set +o allexport

npx prisma migrate diff --from-url "$DATABASE_URL" --to-schema-datamodel prisma/schema.prisma

0 comments on commit ea213c7

Please sign in to comment.