From 840a32b6636b97217adb8bfc75c8a9c22414e5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halvard=20M=C3=B8rstad?= Date: Sun, 31 Oct 2021 10:06:21 +0000 Subject: [PATCH] Added support for custom migration and seed templates (#145) * Added support for custom migration and seed templates * Updated cli usage of the template flags * Updated ci * Added examples and updated readme * Updated changelog --- .github/workflows/ci.yml | 36 +++++++++++----------- CHANGELOG.md | 4 +++ README.md | 44 +++++++++++++++++++++++++-- cli.ts | 22 +++++++++++--- cli/state.ts | 19 +++++++++--- examples/README.md | 4 +++ examples/abstract-classes-extended.ts | 21 +++++++++++++ examples/config-custom-templates.ts | 9 ++++++ examples/migration-template.ts | 17 +++++++++++ examples/seed-template.ts | 13 ++++++++ types.ts | 18 +++++++++++ 11 files changed, 178 insertions(+), 29 deletions(-) create mode 100644 examples/abstract-classes-extended.ts create mode 100644 examples/config-custom-templates.ts create mode 100644 examples/migration-template.ts create mode 100644 examples/seed-template.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef5b676..b113940 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,8 @@ jobs: cli: name: Test CLI runs-on: ubuntu-latest + env: + URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} steps: - name: Install deno @@ -65,50 +67,48 @@ jobs: - name: Nessie Init run: deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts init --dialect sqlite - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} - run: sed -i "s|from \".*\"|from \"https://raw.githubusercontent.com/$URL_PATH/mod.ts\"|" nessie.config.ts && cat nessie.config.ts - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} - name: Create migration run: deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts make test - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} - name: Create migration run: deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts make:migration test2 - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} - name: Create seed run: deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts make:seed test - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} + + - run: echo "test" >> test_template + + - name: Create migration from custom template + run: | + deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts make:migration --migrationTemplate test_template test_migration_template + TEMPLATE_PATH=$(find db/migrations -type f -name "*test_migration_template.ts") + TEMPLATE_CONTENT=$(cat $TEMPLATE_PATH) + if [[ $TEMPLATE_CONTENT != "test" ]]; then echo "File $TEMPLATE_PATH was not correct, was:\n$TEMPLATE_CONTENT" && exit 1; fi + + - name: Create seed from custom template + run: | + deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts make:seed --seedTemplate test_template test_seed_template + TEMPLATE_PATH=$(find db/seeds -type f -name "test_seed_template.ts") + TEMPLATE_CONTENT=$(cat $TEMPLATE_PATH) + if [[ $TEMPLATE_CONTENT != "test" ]]; then echo "File $TEMPLATE_PATH was not correct, was:\n$TEMPLATE_CONTENT" && exit 1; fi - name: Clean files and folders run: rm -rf db && rm -rf nessie.config.ts - name: Init with mode and pg run: deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts init --mode config --dialect pg - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} - name: Init with mode and mysql run: deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts init --mode config --dialect mysql - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} - name: Init with mode and sqlite run: deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts init --mode config --dialect sqlite - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} - name: Init with folders only run: deno run -A --unstable https://raw.githubusercontent.com/$URL_PATH/cli.ts init --mode folders - env: - URL_PATH: ${{github.event.pull_request.head.repo.full_name||github.repository}}/${{github.event.pull_request.head.ref||'main'}} cli-migrations: name: Test CLI Migrations diff --git a/CHANGELOG.md b/CHANGELOG.md index c4ae351..dd28d11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Nessie Change Log +## Next + +- Added support for custom seed and migration templates + ## Version 2.0.3 - 2021-10-30 - Deno v1.15.3 diff --git a/README.md b/README.md index 2fb6b17..4208b89 100644 --- a/README.md +++ b/README.md @@ -116,19 +116,29 @@ information. ``` - `make:migration [name]` & `make [name]`: Create migration, `name` has to be - snake- and lowercase, it can also include numbers. + snake- and lowercase, it can also include numbers. You can also provide the + flag `--migrationTemplate