项目作者: zerg000000

项目描述 :
Ragtime Commandline
高级语言: Clojure
项目地址: git://github.com/zerg000000/ragtime-cli.git
创建时间: 2019-12-10T15:56:16Z
项目社区:https://github.com/zerg000000/ragtime-cli

开源协议:

下载


ragtime-cli

Ragtime Commandline Tools compiled as executable using GraalVM.

Duct Framework is a great framework overall, especially in development time.
However, it is just a bit too slow when it starts or migrates in production or CI test.
By compiling Ragtime to binary, I could at least save half of my CI/CD time (also money)!
And I hope this tools could give others the same benefit!

Usage

You can use it as a commandline tools for db migration.

  1. # command use environment vars
  2. export DATABASE_URL=jdbc:postgresql://localhost:5432/postgres?user=postgres&password=abcd1234
  3. export RESOURCES_DIR=migrations/
  4. export CONFIG_FILE=resources/config.edn
  5. # test connection
  6. ragtime-cli q "select 1"
  7. # show the diff between db and migrations
  8. ragtime-cli info
  9. # migrate
  10. ragtime-cli migrate-all
  11. # rollback-to
  12. ragtime-cli rollback-to <migration-id>
  13. # rollback-last
  14. ragtime-cli rollback-last <n-migrations>
  15. # help
  16. ragtime-cli --help

But it is more useful when used in CI/CD steps or AWS Lambda.
ragtime-cli is already packaged as for lambda deployment.

Package with function

  1. # Download the zip
  2. curl -L https://github.com/zerg000000/ragtime-cli/releases/download/v0.0.4/lambda-ubuntu-latest-postgres.zip -o lambda.zip
  3. # If you are using duct framework, add config.edn and migrations/ to the zip file
  4. zip -ur lambda.zip resources/<project>/config.edn resources/migrations/
  5. # Create Lambda function
  6. aws lambda create-function --function-name db-migration \
  7. --zip-file fileb://lambda.zip --handler index.handler --runtime provided \
  8. --environment Variables="{DATABASE_URL=abc,CONFIG_FILE=resources/<project>/config.edn,RESOURCES_DIR=resources/}" \
  9. --role arn:aws:iam::123456789012:role/lambda-cli-role

Use as a layer

  1. # Download the zip
  2. curl -L https://github.com/zerg000000/ragtime-cli/releases/download/v0.0.4/lambda-ubuntu-latest-postgres.zip -o lambda.zip
  3. # Publish as a layer
  4. aws lambda publish-layer-version --layer-name ragtime-runtime --zip-file fileb://lambda.zip
  5. # Bundle all your migrations files
  6. zip migrations.zip resources/<project>/config.edn resources/migrations/
  7. # Create Lambda function
  8. aws lambda create-function --function-name db-migration \
  9. --layers arn:aws:lambda:us-west-2:123456789012:layer:ragtime-runtime:1 \
  10. --environment Variables="{DATABASE_URL=abc,CONFIG_FILE=resources/<project>/config.edn,RESOURCES_DIR=resources/}" \
  11. --zip-file fileb://migrations.zip

Limitation

Currently, only support/tested on linux/mac and postgres. If your Duct config is not so common,
this commandline might not work for you.

License

Copyright © 2019 Albert Lai

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.