Skip to content

Commit

Permalink
try082
Browse files Browse the repository at this point in the history
Allow `truncate` for SQLite3 adapter and add `rails db:seed:replant`
rails/rails#34779
  • Loading branch information
suketa committed Sep 4, 2019
1 parent aed6f73 commit 606b86a
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 77 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Expand Up @@ -5,7 +5,9 @@ ruby '2.6.4'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use postgresql as the database for Active Record
# Use mysql as the library database for Active Record
gem 'mysql2', '>= 0.4.4'
# Use postgresql as the backbone database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -100,6 +100,7 @@ GEM
mini_portile2 (2.4.0)
minitest (5.11.3)
msgpack (1.3.1)
mysql2 (0.5.2)
nio4r (2.5.1)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
Expand Down Expand Up @@ -206,6 +207,7 @@ DEPENDENCIES
capybara (>= 2.15)
jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2)
mysql2 (>= 0.4.4)
pg (>= 0.18, < 2.0)
puma (~> 3.11)
rails (~> 6.0.0)
Expand Down
2 changes: 2 additions & 0 deletions app/models/book.rb
@@ -0,0 +1,2 @@
class Book < ApplicationRecord
end
2 changes: 2 additions & 0 deletions app/models/user.rb
@@ -0,0 +1,2 @@
class User < ApplicationRecord
end
109 changes: 34 additions & 75 deletions config/database.yml
@@ -1,88 +1,47 @@
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
default_postgresql: &default_postgresql
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: db
host: postgres
user: <%= ENV.fetch("POSTGRES_USER") %>
password: <%= ENV.fetch("POSTGRES_PASSWORD") %>

development:
<<: *default
database: app_development

# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: app

# The password associated with the postgres role (username).
#password:

# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
default_mysql: &default_mysql
adapter: mysql2
encoding: utf8mb4
username: root
password:
host: mysql

# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432

# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public

# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
development:
backbone:
<<: *default_postgresql
database: backbone_development
library:
<<: *default_mysql
database: library_development
migrations_paths: db/library_migrate

# 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: app_test
backbone:
<<: *default_postgresql
database: backbone_test
library:
<<: *default_mysql
database: library_test
migrations_paths: db/library_migrate

# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: app_production
username: app
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
backbone:
<<: *default_postgresql
database: backbone_production
username: backbone
password: <%= ENV['BACKBONE_DATABASE_PASSWORD'] %>
library:
<<: *default_mysql
database: library_production
migrations_paths: db/library_migrate
username: library
password: <%= ENV['LIBRARY_DATABASE_PASSWORD'] %>
9 changes: 9 additions & 0 deletions db/library_migrate/20190904113005_create_books.rb
@@ -0,0 +1,9 @@
class CreateBooks < ActiveRecord::Migration[6.0]
def change
create_table :books do |t|
t.string :title

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20190904112936_create_users.rb
@@ -0,0 +1,9 @@
class CreateUsers < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
t.string :name

t.timestamps
end
end
end
12 changes: 11 additions & 1 deletion docker-compose.yml
Expand Up @@ -12,16 +12,26 @@ services:
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
db:
postgres:
image: postgres:10.7-alpine
volumes:
- pgsqldb:/var/lib/postgresql/data
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD

mysql:
image: mysql:8.0.17
command: --default-authentication-plugin=mysql_native_password
volumes:
- mysqldb:/var/lib/mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'

volumes:
pgsqldb:
driver: local
mysqldb:
driver: local
bundle:
driver: local
7 changes: 7 additions & 0 deletions test/fixtures/books.yml
@@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
title: MyString

two:
title: MyString
7 changes: 7 additions & 0 deletions test/fixtures/users.yml
@@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString

two:
name: MyString
7 changes: 7 additions & 0 deletions test/models/book_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class BookTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/user_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 606b86a

Please sign in to comment.