Skip to content

Commit

Permalink
[mod] change db mysql->postgres (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
大浦 翼 committed May 29, 2023
1 parent fea1214 commit 3d2a6b0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 49 deletions.
3 changes: 2 additions & 1 deletion api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.1'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.5'
# gem 'mysql2', '~> 0.5'
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Expand Down
4 changes: 2 additions & 2 deletions api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ GEM
mini_portile2 (2.6.1)
minitest (5.14.4)
msgpack (1.4.2)
mysql2 (0.5.3)
nio4r (2.5.8)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
orm_adapter (0.5.0)
pg (1.5.3)
puma (5.5.2)
nio4r (~> 2.0)
racc (1.6.0)
Expand Down Expand Up @@ -196,7 +196,7 @@ DEPENDENCIES
devise_token_auth
dotenv-rails
listen (~> 3.3)
mysql2 (~> 0.5)
pg (~> 1.1)
puma (~> 5.0)
rack-cors
rails (~> 6.1.3, >= 6.1.3.1)
Expand Down
7 changes: 3 additions & 4 deletions api/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
#
default: &default
adapter: mysql2
encoding: utf8mb4
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
username: seeds
password: password
host: seeds_db
socket: /tmp/myapp.sock

development:
<<: *default
Expand Down
39 changes: 21 additions & 18 deletions api/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@

ActiveRecord::Schema.define(version: 2023_02_21_091509) do

create_table "bureaus", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "bureaus", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "categories", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "detail"
end

create_table "chapters", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "chapters", force: :cascade do |t|
t.string "title"
t.text "content"
t.text "homework"
Expand All @@ -35,49 +38,49 @@
t.integer "order"
end

create_table "curriculum_skills", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "curriculum_skills", force: :cascade do |t|
t.integer "curriculum_id"
t.integer "skill_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "curriculums", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "curriculums", force: :cascade do |t|
t.string "title"
t.integer "skill_ids"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.text "graduation_assignment"
end

create_table "departments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "departments", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "grades", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "grades", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "project_skills", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "project_skills", force: :cascade do |t|
t.integer "project_id"
t.integer "skill_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "project_users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "project_users", force: :cascade do |t|
t.integer "project_id"
t.integer "user_id"
t.integer "role_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "projects", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "projects", force: :cascade do |t|
t.string "name"
t.string "detail"
t.string "icon_name"
Expand All @@ -87,7 +90,7 @@
t.datetime "updated_at", precision: 6, null: false
end

create_table "records", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "records", force: :cascade do |t|
t.string "title"
t.text "content"
t.text "homework"
Expand All @@ -97,13 +100,13 @@
t.integer "chapter_id"
end

create_table "roles", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "roles", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "skills", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "skills", force: :cascade do |t|
t.string "name"
t.string "detail"
t.integer "category_id"
Expand All @@ -112,20 +115,20 @@
t.integer "type_id"
end

create_table "teachers", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "teachers", force: :cascade do |t|
t.integer "user_id"
t.integer "record_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "types", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "types", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "user_details", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "user_details", force: :cascade do |t|
t.integer "user_id"
t.integer "grade_id"
t.integer "department_id"
Expand All @@ -144,14 +147,14 @@
t.integer "type_id"
end

create_table "user_skills", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "user_skills", force: :cascade do |t|
t.integer "user_id"
t.integer "skill_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "users", force: :cascade do |t|
t.string "provider", default: "email", null: false
t.string "uid", default: "", null: false
t.string "encrypted_password", default: "", null: false
Expand Down
35 changes: 11 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
version: "3"
services:
seeds_db:
image: mysql:8.0
container_name: "seeds_db"
environment:
MYSQL_ROOT_PASSWORD: password
ports:
- "3306:3306"
command: --default-authentication-plugin=mysql_native_password
image: postgres:12
volumes:
- mysql-data:/var/lib/mysql
- mysql-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: myapp_development
POSTGRES_USER: seeds
POSTGRES_PASSWORD: password
POSTGRES_HOST_AUTH_METHOD: trust

seeds_api:
build: ./api
Expand All @@ -20,9 +19,8 @@ services:
volumes:
- ./api:/myapp
depends_on:
- seeds_db
stdin_open: true
tty: true
seeds_db:
condition: service_started

seeds_view:
build: ./view
Expand All @@ -32,22 +30,11 @@ services:
command: sh -c "npm install && npm run dev"
volumes:
- ./view:/app
stdin_open: true
tty: true
environment:
- SEEDS_API_URI=http://localhost:3000

# 定期実行用コンテナ
cron:
image: nutmeg-seeds-seeds_api:latest
command: >
sh -c "whenever --update-cron &&
cron -f -l 2"
restart: always
volumes:
- ./api:/usr/src/app
depends_on:
- seeds_api
seeds_api:
condition: service_started

volumes:
mysql-data:
Expand Down

0 comments on commit 3d2a6b0

Please sign in to comment.