Sha256: 663870caecb07cdfabe585885b2af251c9e581978da2e03aa21f54e5729c24e8

Contents?: true

Size: 777 Bytes

Versions: 1

Compression:

Stored size: 777 Bytes

Contents

module Caco::Postgres
  class DatabaseCreate < Trailblazer::Operation

    step Subprocess(Caco::Postgres::Sql),
      input: ->(_ctx, database:, **) {{
        sql: "select datname from pg_database where datname='#{database}';",
      }},
      id: :sql_find_database

    step ->(_ctx, output:, database:, **) {
        output.match?(/^\s#{database}$/)
      },
      Output(:success) => End(:success),
      Output(:failure) => Track(:success),
      id: :verify_database_exists

    step Subprocess(Caco::Executer),
      input: ->(ctx, database:, **) {{
        command: "createdb -e #{ctx[:additional_args]} #{database}",
      }},
      id: :create_database

    step ->(ctx, **) {
        ctx[:created] = ctx[:changed] = true
      },
      id: :mark_created
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caco-0.1.0 lib/caco/postgres/database_create.rb