Skip to content

Commit

Permalink
use Rails' DB tasks instead (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
eitoball authored Oct 23, 2022
1 parent 725c687 commit fdcd5ef
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 108 deletions.
13 changes: 4 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ jobs:
docker:
- image: safecast/api-build:2.7.6-amazonlinux2
environment:
RAILS_ENV: test
AWS_DEFAULT_REGION: us-west-2
EB_APP_NAME: api
PYTHON_BIN: python3.8
RAILS_ENV: test
- image: mdillon/postgis:11
environment:
POSTGRES_USER: safecast
POSTGRES_DB: safecast
POSTGRES_PASSWORD: ""
POSTGRES_USER: safecast
- image: docker.elastic.co/elasticsearch/elasticsearch:7.5.0
environment:
discovery.type: single-node
Expand All @@ -25,7 +25,6 @@ jobs:
- run:
name: Bundle Install
command: |
gem install bundler -v 2.2.29
bundle install --path vendor/bundle --jobs 2 --retry 3
- save_cache:
key: v5-safecastapi-{{ checksum "Gemfile.lock" }}
Expand All @@ -37,22 +36,18 @@ jobs:
- run:
name: Wait for elasticsearch
command: dockerize -wait tcp://localhost:9200 -timeout 1m
- run:
name: Configure database
command: cp config/database.yml.ci config/database.yml
- run:
name: Load schema
command: |
psql -h localhost -p 5432 -U safecast safecast -c 'DROP EXTENSION postgis CASCADE'
bundle exec rake db:schema:load --trace
bundle exec rails db:create db:structure:load
- run:
name: Run rubocop
command: |
bundle exec rubocop -P
- run:
name: Run assets precompile
command: |
bundle exec rake assets:precompile
bundle exec rails assets:precompile
- run:
name: Run rspec
command: |
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Application < Rails::Application
config.active_job.queue_adapter = :delayed_job

config.active_record.schema_format = :sql
config.active_record.dump_schemas = :all
config.active_record.yaml_column_permitted_classes = [
ActiveSupport::HashWithIndifferentAccess,
Symbol
Expand Down
28 changes: 16 additions & 12 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
default: &default
adapter: postgis
pool: 5
timeout: 5000
schema_search_path: public,postgis
encoding: unicode
username: safecast
password:
host: <%= ENV.fetch('DATABASE_HOST', 'localhost' ) %>
adapter: postgis
encoding: unicode
host: <%= ENV.fetch('DATABASE_HOST', 'localhost') %>
pool: 5
port: 5432
postgis_extension: postgis
postgis_schema: postgis
schema_search_path: public,postgis
su_password:
su_username: safecast
timeout: 5000

development:
<<: *default
database: <%= ENV.fetch('DATABASE_NAME_DEVELOPMENT', 'safecast_development' ) %>
username: <%= ENV.fetch('DATABASE_POSTGRESQL_USERNAME', 'safecast' ) %>
password: <%= ENV.fetch('DATABASE_POSTGRESQL_PASSWORD', '' ) %>
database: <%= ENV.fetch('DATABASE_NAME_DEVELOPMENT', 'safecast_development') %>
username: <%= ENV.fetch('DATABASE_POSTGRESQL_USERNAME', 'safecast') %>
password: <%= ENV.fetch('DATABASE_POSTGRESQL_PASSWORD', '') %>

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: <%= ENV.fetch('DATABASE_NAME_TEST', 'safecast_test' ) %>
username: <%= ENV.fetch('DATABASE_POSTGRESQL_USERNAME', 'safecast' ) %>
password: <%= ENV.fetch('DATABASE_POSTGRESQL_PASSWORD', '' ) %>
database: <%= ENV.fetch('DATABASE_NAME_TEST', 'safecast_test') %>
username: <%= ENV.fetch('DATABASE_POSTGRESQL_USERNAME', 'safecast') %>
password: <%= ENV.fetch('DATABASE_POSTGRESQL_PASSWORD', '') %>

production:
<<: *default
Expand Down
6 changes: 0 additions & 6 deletions config/database.yml.ci

This file was deleted.

30 changes: 12 additions & 18 deletions db/structure.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 11.2 (Debian 11.2-1.pgdg90+1)
-- Dumped by pg_dump version 13.2

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
Expand All @@ -20,7 +13,14 @@ SET row_security = off;
-- Name: postgis; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA postgis;
CREATE SCHEMA IF NOT EXISTS postgis;


--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

-- *not* creating schema, since initdb creates it


--
Expand Down Expand Up @@ -218,6 +218,7 @@ CREATE SEQUENCE public.bgeigie_logs_id_seq

ALTER SEQUENCE public.bgeigie_logs_id_seq OWNED BY public.bgeigie_logs.id;


--
-- Name: configurables; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -928,7 +929,6 @@ ALTER TABLE ONLY public.bgeigie_logs
ADD CONSTRAINT bgeigie_logs_pkey PRIMARY KEY (id);


--
--
-- Name: configurables configurables_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1327,14 +1327,6 @@ CREATE UNIQUE INDEX index_users_on_reset_password_token ON public.users USING bt
CREATE UNIQUE INDEX unique_schema_migrations ON public.schema_migrations USING btree (version);


--
-- Name: comments fk_rails_03de2dc08c; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.comments
ADD CONSTRAINT fk_rails_03de2dc08c FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- Name: device_story_comments fk_rails_0d30498751; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1363,7 +1355,9 @@ ALTER TABLE ONLY public.active_storage_attachments
-- PostgreSQL database dump complete
--

INSERT INTO public.schema_migrations (version) VALUES
SET search_path TO public,postgis;

INSERT INTO "schema_migrations" (version) VALUES
('20111123174941'),
('20111123190839'),
('20111124211843'),
Expand Down
63 changes: 0 additions & 63 deletions lib/tasks/db.rake

This file was deleted.

0 comments on commit fdcd5ef

Please sign in to comment.