Skip to content

Commit

Permalink
try067
Browse files Browse the repository at this point in the history
MySQL: Support `:size` option to change text and blob size
rails/rails#35071
  • Loading branch information
suketa committed Jul 27, 2019
1 parent ddb842d commit c5e28e8
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class User < ApplicationRecord
end
14 changes: 12 additions & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@
# Configure Using Gemfile
# gem 'pg'
#

# mysql2
# default: &default
# adapter: mysql2
# encoding: utf8mb4
# pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
# username: root
# password: <%= ENV.fetch('MYSQL_ROOT_PASSWORD') %>
# host: db_mysql

default: &default
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 } %>
username: <%= ENV.fetch('POSTGRES_USER') %>
password: <%= ENV.fetch('POSTGRES_PASSWORD') %>
host: db
user: <%= ENV.fetch("POSTGRES_USER") %>
password: <%= ENV.fetch("POSTGRES_PASSWORD") %>

development:
<<: *default
Expand Down
7 changes: 0 additions & 7 deletions db/migrate/20190720124709_create_user.rb

This file was deleted.

16 changes: 16 additions & 0 deletions db/migrate/20190726231951_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateUsers < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
t.string :name
t.text :profile0
t.text :profile1, limit: 255
t.text :profile2, limit: 16777215
t.text :profile3 # , limit: 4294967295
t.text :profile4, size: :tiny
t.text :profile5, size: :medium
t.text :profile6, size: :long

t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_07_20_124709) do
ActiveRecord::Schema.define(version: 2019_07_26_231951) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "users", force: :cascade do |t|
t.string "name"
t.text "profile0"
t.text "profile1"
t.text "profile2"
t.text "profile3"
t.text "profile4"
t.text "profile5"
t.text "profile6"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end
28 changes: 28 additions & 0 deletions db/schema_mysql.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_07_26_231951) do

create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name"
t.text "profile0"
t.text "profile1", size: :tiny
t.text "profile2", size: :medium
t.text "profile3", size: :long
t.text "profile4", size: :tiny
t.text "profile5", size: :medium
t.text "profile6", size: :long
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end
19 changes: 19 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString
profile1: MyText
profile2: MyText
profile3: MyText
profile4: MyText
profile5: MyText
profile6: MyText

two:
name: MyString
profile1: MyText
profile2: MyText
profile3: MyText
profile4: MyText
profile5: MyText
profile6: MyText
7 changes: 7 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

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

0 comments on commit c5e28e8

Please sign in to comment.