Sha256: 24e8f9934ea51aaa5248b6ea624c27f8704fca32b5dd55d7f019c6b5527c663d

Contents?: true

Size: 1.7 KB

Versions: 74

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require_relative "../../lib/plutonium_generators"

module Pu
  module Service
    class PostgresGenerator < Rails::Generators::Base
      include PlutoniumGenerators::Generator

      source_root File.expand_path("templates", __dir__)

      desc "Set up postgres for project"

      def start
        bundle "goldiloader"
        template "database.yml", "config/database.yml", force: true
        bin_directory
        add_compose_env :POSTGRES_HOST, service
        add_compose_dependency service
        add_compose_service service, compose_config
        add_docker_dependency docker_deps
      rescue => e
        exception "#{self.class} failed:", e
      end

      private

      def service
        :postgres
      end

      def compose_config
        <<~COMPOSE
          postgres:
            image: postgres:15 # postgres
            # postgres properties
            environment: # postgres
              POSTGRES_MULTIPLE_DATABASES: #{db_prefix}_development,#{db_prefix}_test # postgres
              POSTGRES_USER: postgres # postgres
              POSTGRES_PASSWORD: postgres # postgres
            volumes: # postgres
            - "./.volumes/postgres/data:/var/lib/postgresql/data" # postgres
            - "./bin/initdb.d:/docker-entrypoint-initdb.d" # postgres
        COMPOSE
      end

      def docker_deps
        <<~DEPS
          # Install packages needed for postgres
          RUN apt-get update -qq && \\
              apt-get install --no-install-recommends -y curl postgresql-client && \\
              rm -rf /var/lib/apt/lists /var/cache/apt/archives
        DEPS
      end

      def db_prefix
        Plutonium.application_name.underscore
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
plutonium-0.16.3 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.16.1 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.16.0 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.24 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.23 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.22 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.21 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.20 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.19 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.18 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.17 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.16 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.15 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.14 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.13 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.12 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.11 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.10 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.9 lib/generators/pu/service/postgres/postgres_generator.rb
plutonium-0.15.8 lib/generators/pu/service/postgres/postgres_generator.rb