Skip to content

Commit

Permalink
try065
Browse files Browse the repository at this point in the history
Make `t.timestamps` with precision by default
rails/rails#34970
  • Loading branch information
suketa committed Jul 26, 2019
1 parent d9eae5e commit 971f3dc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
8 changes: 8 additions & 0 deletions app/models/user.rb
@@ -0,0 +1,8 @@
class User < ApplicationRecord
scope :find_first, -> {
created_at = first.created_at
t = Time.new(created_at.year, created_at.month, created_at.day, created_at.hour, created_at.min, created_at.sec)
# t = Time.new(created_at.year, created_at.month, created_at.day, created_at.hour, created_at.min, created_at.sec) + created_at.subsec
where(created_at: t)
}
end
9 changes: 9 additions & 0 deletions db/migrate/20190726065102_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
21 changes: 21 additions & 0 deletions db/schema.rb
@@ -0,0 +1,21 @@
# 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_065102) do

create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end
8 changes: 1 addition & 7 deletions db/seeds.rb
@@ -1,7 +1 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
User.create(name: 'Taro')
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/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 971f3dc

Please sign in to comment.