Skip to content

Instantly share code, notes, and snippets.

@pioz
Last active September 19, 2022 07:25
Show Gist options
  • Save pioz/156ec1d0f37008f819f55f5abac137f7 to your computer and use it in GitHub Desktop.
Save pioz/156ec1d0f37008f819f55f5abac137f7 to your computer and use it in GitHub Desktop.
Active Record in script
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord'
gem 'pg'
end
require 'active_record'
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class Post < ApplicationRecord
end
def migrate
ActiveRecord::Schema.define do
create_table(:posts) do |t|
t.string :name
t.string :column1
t.string :column2
t.string :column3
t.jsonb :data
end
end
end
migrate
records = 1_000_000.times.map do |i|
{ name: "foo#{i}", column1: 'value1', column2: 'value2', column3: 'value3', data: ['IT', 'FR'] }
end
Post.insert_all(records)
Post.create!(name: 'foo yeah', column1: 'value1', column2: 'value2', column3: 'value3', data: ['foo', 'FR'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment