From c3440de7ae8ae4cb55db8f5d8e178a8539959ee7 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 24 Sep 2019 14:56:04 -0300 Subject: [PATCH] migrar a postgresql --- Dockerfile | 2 +- Gemfile | 2 ++ Gemfile.lock | 11 +++++++++++ Procfile | 2 +- bin/migrate_database | 18 ++++++++++++++++++ config/database.yml.pg | 7 +++++++ monit.conf | 2 +- 7 files changed, 41 insertions(+), 3 deletions(-) create mode 100755 bin/migrate_database create mode 100644 config/database.yml.pg diff --git a/Dockerfile b/Dockerfile index a3256076..ab75f552 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,7 +60,7 @@ ENV RAILS_ENV production # Instalar las dependencias, separamos la librería de base de datos para # poder reutilizar este primer paso desde otros contenedores RUN apk add --no-cache libxslt libxml2 tzdata ruby ruby-bundler ruby-json ruby-bigdecimal ruby-rake -RUN apk add --no-cache sqlite-libs +RUN apk add --no-cache sqlite-libs postgresql-libs # Necesitamos yarn para que Jekyll pueda generar los sitios # XXX: Eliminarlo cuando extraigamos la generación de sitios del proceso # principal diff --git a/Gemfile b/Gemfile index 2762e173..98c0adc0 100644 --- a/Gemfile +++ b/Gemfile @@ -56,6 +56,7 @@ gem 'inline_svg' gem 'jekyll' gem 'mini_magick' gem 'mobility' +gem 'pg' gem 'pundit' gem 'rails-i18n' gem 'rails_warden' @@ -67,6 +68,7 @@ gem 'rugged' gem 'sucker_punch' gem 'terminal-table' gem 'validates_hostname' +gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git' gem 'webpacker' group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index b1bf2664..2fa3fdf3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,6 +5,14 @@ GIT reverse_markdown (1.2.0) nokogiri +GIT + remote: https://0xacab.org/sutty/yaml_db.git + revision: 40e44c29ce4290dfe4013ff4fce1be5a936fedf4 + specs: + yaml_db (0.7.0) + rails (>= 3.0) + rake (>= 0.8.7) + GEM remote: https://gems.sutty.nl/ specs: @@ -242,6 +250,7 @@ GEM ast (~> 2.4.0) pathutil (0.16.2) forwardable-extended (~> 2.6) + pg (1.1.4) popper_js (1.14.5) pry (0.12.2) coderay (~> 1.1.0) @@ -450,6 +459,7 @@ DEPENDENCIES listen (>= 3.0.5, < 3.2) mini_magick mobility + pg pry puma (~> 3.7) pundit @@ -475,6 +485,7 @@ DEPENDENCIES validates_hostname web-console (>= 3.3.0) webpacker + yaml_db! BUNDLED WITH 2.0.2 diff --git a/Procfile b/Procfile index c2eadd25..0b9409e3 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -migrate: if test -f data/production.sqlite3; then bundle exec rake db:migrate db:seed ; else bundle exec rake db:setup ; fi +migrate: bundle exec rake db:prepare db:seed sutty: bundle exec puma -d config.ru diff --git a/bin/migrate_database b/bin/migrate_database new file mode 100755 index 00000000..62dc8462 --- /dev/null +++ b/bin/migrate_database @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +cd /srv/http + +test -f data/production.sqlite3.migrated && exit 0 + +bundle exec rake db:data:dump_dir dir=data +cat config/database.yml.pg > config/database.yml + +bundle exec rake db:schema:load + +rm db/data/ar_internal_metadata.yml +mv db/data/active_storage_attachments.yml db/data/zz_active_storage_attachments.yml + +bundle exec rake db:load dir=data truncate=false + +mv data/production.sqlite3 data/production.sqlite3.migrated diff --git a/config/database.yml.pg b/config/database.yml.pg new file mode 100644 index 00000000..c4d92834 --- /dev/null +++ b/config/database.yml.pg @@ -0,0 +1,7 @@ +production: + adapter: postgresql + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + database: sutty + user: sutty + host: postgresql + encoding: unicode diff --git a/monit.conf b/monit.conf index 4d34d69c..9f002db6 100644 --- a/monit.conf +++ b/monit.conf @@ -1,5 +1,5 @@ check process sutty with pidfile /srv/http/tmp/puma.pid - start program = "/bin/sh -c 'cd /srv/http && foreman start migrate && foreman start sutty'" as uid app + start program = "/bin/sh -c 'cd /srv/http && ./bin/migrate_database && foreman start migrate && foreman start sutty'" as uid app stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'" check program sync_assets