Skip to content

Instantly share code, notes, and snippets.

View attilahorvath's full-sized avatar

Attila Horváth attilahorvath

  • Dublin, Ireland
View GitHub Profile
@attilahorvath
attilahorvath / tar_compress_extract_directory.sh
Last active August 29, 2015 14:17
Tar compress/extract directory
# compress
tar -czvf archive.tar.gz directory
# extract
tar -xzvf archive.tar.gz
# flags:
# (c)reate
# e(x)tract
# use g(z)ip
@attilahorvath
attilahorvath / migrate_to_utf8mb4.rb
Created March 3, 2015 16:08
Migrate entire MySQL database to utf8mb4 encoding
class MigrateToUtf8mb4 < ActiveRecord::Migration
def change
execute "ALTER DATABASE `#{ActiveRecord::Base.connection.current_database}` CHARACTER SET utf8mb4;"
ActiveRecord::Base.connection.tables.each do |table|
execute "ALTER TABLE `#{table}` CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;"
ActiveRecord::Base.connection.columns(table).each do |column|
if column.sql_type =~ /varchar\((\d+)\)/
limit = $1.to_i
limit = 191 if ActiveRecord::Base.connection.indexes(table).any?{|i| i.columns.include? column.name} && limit > 191