Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash console session demonstrating failure to hack activerecord.
kendall@kendall:~$ rvm 1.9.2@rails
kendall@kendall:~$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
kendall@kendall:~$ gem -v
1.5.0
kendall@kendall:~$ rails new timestamp
create
create [...lines ommitted for brevity...]
kendall@kendall:~$ cd timestamp/
kendall@kendall:~/timestamp$ vi Gemfile
kendall@kendall:~/timestamp$ bundle install
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.5)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.5)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.7)
Using tzinfo (0.3.24)
Using actionpack (3.0.5)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.15)
Using actionmailer (3.0.5)
Using arel (2.0.9)
Using activerecord (3.0.5)
Using activeresource (3.0.5)
Using bundler (1.0.10)
Using mysql2 (0.2.6)
Using thor (0.14.6)
Using railties (3.0.5)
Using rails (3.0.5)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
kendall@kendall:~/timestamp$ bundle show activerecord
/usr/local/rvm/gems/ruby-1.9.2-p136@rails/gems/activerecord-3.0.5
kendall@kendall:~/timestamp$ ln -s /usr/local/rvm/gems/ruby-1.9.2-p136@rails/gems/activerecord-3.0.5/lib/active_record
kendall@kendall:~/timestamp$ vi config/database.yml
kendall@kendall:~/timestamp$ cat config/database.yml
development:
adapter: mysql2
host: localhost
database: timestamp_development
username: dev
password: ********
test:
adapter: mysql2
host: localhost
database: timestamp_test
username: dev
password: ********
production:
adapter: mysql2
host: localhost
database: timestamp_production
username: dev
password: ********
kendall@kendall:~/timestamp$ mysql -u kendall -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.1.49-1ubuntu8.1 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT ALL PRIVILEGES ON timestamp_development.* TO 'dev'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON timestamp_test.* TO 'dev'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON timestamp_production.* TO 'dev'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
kendall@kendall:~/timestamp$ rake db:create
(in /home/kendall/timestamp)
kendall@kendall:~/timestamp$ ls -la active_record
lrwxrwxrwx 1 kendall kendall 83 2011-03-03 11:06 active_record -> /usr/local/rvm/gems/ruby-1.9.2-p136@rails/gems/activerecord-3.0.5/lib/active_record
kendall@kendall:~/timestamp$ cp active_record/connection_adapters/mysql_adapter.rb ./mysql_adapter.rb-orig
kendall@kendall:~/timestamp$ cp ./mysql_adapter.rb-orig ./mysql_adapter.rb-new
kendall@kendall:~/timestamp$ vi ./mysql_adapter.rb-new
kendall@kendall:~/timestamp$ diff active_record/connection_adapters/mysql_adapter.rb ./mysql_adapter.rb-new
153c153
< :timestamp => { :name => "datetime" },
---
> :timestamp => { :name => "timestamp" },
kendall@kendall:~/timestamp$ rails g model WithoutPatch fld:timestamp
invoke active_record
create db/migrate/20110303212138_create_without_patches.rb
create app/models/without_patch.rb
invoke test_unit
create test/unit/without_patch_test.rb
create test/fixtures/without_patches.yml
kendall@kendall:~/timestamp$ cat db/migrate/20110303212138_create_without_patches.rb
class CreateWithoutPatches < ActiveRecord::Migration
def self.up
create_table :without_patches do |t|
t.timestamp :fld
t.timestamps
end
end
def self.down
drop_table :without_patches
end
end
kendall@kendall:~/timestamp$ rake db:migrate
(in /home/kendall/timestamp)
== CreateWithoutPatches: migrating ===========================================
-- create_table(:without_patches)
-> 0.1153s
== CreateWithoutPatches: migrated (0.1154s) ==================================
kendall@kendall:~/timestamp$ mysql -u dev -p timestamp_development
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 45
Server version: 5.1.49-1ubuntu8.1 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> describe without_patches;
+------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| fld | datetime | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+------------+----------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> exit
Bye
kendall@kendall:~/timestamp$ sudo cp mysql_adapter.rb-new active_record/connection_adapters/mysql_adapter.rb
[sudo] password for kendall:
kendall@kendall:~/timestamp$ rails g model WithPatch fld:timestamp
invoke active_record
create db/migrate/20110303212424_create_with_patches.rb
create app/models/with_patch.rb
invoke test_unit
create test/unit/with_patch_test.rb
create test/fixtures/with_patches.yml
kendall@kendall:~/timestamp$ cat db/migrate/20110303212424_create_with_patches.rb
class CreateWithPatches < ActiveRecord::Migration
def self.up
create_table :with_patches do |t|
t.timestamp :fld
t.timestamps
end
end
def self.down
drop_table :with_patches
end
end
kendall@kendall:~/timestamp$ rake db:migrate
(in /home/kendall/timestamp)
== CreateWithPatches: migrating ==============================================
-- create_table(:with_patches)
-> 0.1402s
== CreateWithPatches: migrated (0.1403s) =====================================
kendall@kendall:~/timestamp$ mysql -u dev -p timestamp_development
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 46
Server version: 5.1.49-1ubuntu8.1 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> describe with_patches;
+------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| fld | datetime | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+------------+----------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
kendall@kendall:~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment