Commit Graph

5424 Commits

Author SHA1 Message Date
Jon Leighton
18bf30982b Cache column defaults on model. ~30% on Model.new due to avoiding repeatedly fetching connection. 2011-12-14 16:14:47 +00:00
Jon Leighton
7b0edbb9f2 Avoid super; speeds up Model.new by about 12% 2011-12-14 16:14:47 +00:00
Jon Leighton
19bea9f1bd Stop the build asploding on 1.8.7 2011-12-14 15:31:12 +00:00
Jon Leighton
bb44e5a80a Use a separate module for 'external' attribute methods. 2011-12-14 14:51:57 +00:00
Jon Leighton
38703ac897 Revert naive O(1) table_exists? implementation.
It was a bad idea to rescue exceptions here. This can interfere with
transaction rollbacks which seems to be the cause of current CI
failure.

Instead, each adapter should implement its own DB-specific O(1)
implementation, and we fall back on the generic, slower, implementation
otherwise.
2011-12-13 23:46:26 +00:00
Vijay Dev
74e46e5156 Merge branch 'master' of github.com:lifo/docrails 2011-12-14 02:13:23 +05:30
José Valim
80256abb39 FileUpdateChecker should be able to handle deleted files. 2011-12-13 11:23:21 +01:00
Aaron Patterson
d12e6d0e2f use the schema cache when asking for the primary key 2011-12-12 15:59:44 -08:00
José Valim
fa1d9a884c Speed up development by only reloading classes if dependencies files changed.
This can be turned off by setting `config.reload_classes_only_on_change` to false.

Extensions like Active Record should add their respective files like db/schema.rb and db/structure.sql to `config.watchable_files` if they want their changes to affect classes reloading.

Thanks to https://github.com/paneq/active_reload and Pastorino for the inspiration. <3
2011-12-12 22:54:04 +01:00
clst
2be6df693a changed :finder_sql example to select *
because with select p.* you can no longer use count(). Using count will result in an SQL error message.
2011-12-12 18:27:51 +01:00
clst
a6b15bd2dc fixed example for :finder_sql
people.* will not work when the alias is named p
2011-12-12 15:46:42 +01:00
Aaron Patterson
d102791df7 ensure @fixture_connections is initialized in case an exception happens during setup 2011-12-10 16:33:08 -08:00
Aaron Patterson
d09b67cfc0 Errno::ENOENT error makes more sense when a file cannot be found 2011-12-10 16:32:07 -08:00
Piotr Sarnacki
35a1744a45 Allow to run migrations with given scope, with SCOPE=<scope>
Scope in migrations can be defined by adding suffix in filename,
like: 01_a_migration.blog.rb. Such migration have blog scope.

Scope is automatically added while copying migrations from engine,
so if you want to revert all of the migrations from given engine,
you can just run db:migrate with SCOPE, like:

    rake db:migrate SCOPE=blog
2011-12-09 22:00:51 +01:00
Piotr Sarnacki
f0b782d060 Allow to filter migrations by passing a block
Example:
  ActiveRecord::Migrator.migrate(path) do |migration|
    migration.name =~ /User/
  end

The above example will migrate only migrations with User in
the name
2011-12-09 21:43:36 +01:00
Aaron Patterson
5b82f50fef Use table_exists? from the schema cache. 2011-12-09 11:23:19 -08:00
Aaron Patterson
007965a651 don't need a begin / end. 2011-12-09 10:18:10 -08:00
Aaron Patterson
a29d1dbd59 squelch table exists? queries. 2011-12-09 10:14:49 -08:00
Piotr Sarnacki
929b2646b6 Compare migrations for copying only by name and scope 2011-12-09 12:15:54 +01:00
Piotr Sarnacki
ed0b1f6eed Add suffix for migrations copied from engines 2011-12-09 11:45:19 +01:00
Piotr Sarnacki
255d9f5ac1 String#to_a is not available in 1.9 2011-12-09 10:33:37 +01:00
Piotr Sarnacki
1d9de9d758 Run also migrations in subdirectories.
With this commit, ActiveRecord will also look for migrations
in db/migrate subdirectories.
2011-12-09 03:33:06 +01:00
Piotr Sarnacki
62d556424a Ignore origin comment when checking for duplicates on Migration.copy
49ebe51 fixed copying migrations, but existing migrations would still
trigger warnings. The proper way to compare migrations is to ignore
origin lines - if migration is identical it means that we can
silently skip it, regardless where it comes from.
2011-12-09 01:54:20 +01:00
Piotr Sarnacki
652db2fc3e Fix copying migrations from engines
There was a bug in ActiveRecord::Migration.copy method, which
prevented adding special comment about the origin of migration.

Because of that, the check if migration is identical or if it's
not and should be skipped was always saying that migration is
skipped, which was causing additional useless warnings about
skipped migrations.
2011-12-09 01:54:20 +01:00
Aaron Patterson
8c26cd5d97 Exceptions should read from the spec configu 2011-12-08 15:14:07 -08:00
Jon Leighton
5da90b3483 Fix #3890. (Calling proxy_association in scope chain.) 2011-12-08 20:10:04 +00:00
Vijay Dev
94dcbe8115 fix nodocs 2011-12-09 01:15:54 +05:30
Vijay Dev
965f6f22aa fix comments 2011-12-09 01:02:27 +05:30
José Valim
d1abf29e79 Remove NilClass whiners feature.
Removing this feature causes boost in performance when using Ruby 1.9.

Ruby 1.9 started to do implicit conversions using `to_ary` and `to_str`
in some STDLIB methods (like Array#join). To do such implicit conversions,
Ruby 1.9 always dispatches the method and rescues the NoMethodError exception
in case one is raised.

Therefore, since the whiners feature defined NilClass#method_missing, such
implicit conversions for nil became much, much slower. In fact, just defining
NilClass#method_missing (even without the whiners feature) already causes a
massive slow down. Here is a snippet that shows such slow down:

    require "benchmark"
    Benchmark.realtime { 1_000.times { [nil,nil,nil].join } }

    class NilClass
      def method_missing(*args)
        raise NoMethodError
      end
    end

    Benchmark.realtime { 1_000.times { [nil,nil,nil].join } }
2011-12-08 20:28:09 +01:00
Aaron Patterson
3cae753963 fixing eval'd line numbers. 2011-12-08 10:39:12 -08:00
Aaron Patterson
76c29a64b9 Use a hash to look up column definitions 2011-12-07 17:25:31 -08:00
Aaron Patterson
7e176a6d12 try to normalize the objects passed to column() 2011-12-07 16:18:39 -08:00
Aaron Patterson
483a3cf287 automatically add the column definition to the columns list if creating a new one 2011-12-07 16:01:53 -08:00
Aaron Patterson
1fc47a1a84 stop calling String#to_s so frequently 2011-12-07 15:35:27 -08:00
Aaron Patterson
8523784265 the required sqlite3 adapter responds to encoding, so stop checking. 2011-12-07 15:01:04 -08:00
Evgeniy Kelyarsky
dd647d938e reversible migration example had missing block parameter 2011-12-07 17:03:51 +02:00
Vasiliy Ermolovich
0968ee3456 add prefix and suffix to renamed tables, closes #1510 2011-12-06 10:02:45 -08:00
Aaron Patterson
8aa7b8695d Quitoting the table name before querying. 2011-12-05 14:20:14 -08:00
Jade Rubick
73a331c2ac Speed up table_exists? for databases with a large number of tables
At New Relic, we have hundreds of thousands of tables, and our migrations took 30 minutes without this similar patch. This cuts it down to a more reasonable amount of time.

The rescue false part is ugly, but necessary as far as I can tell. I don't know of a cross-database statement you can make that will work without trapping errors.
2011-12-05 11:20:10 -08:00
José Valim
cf6ccf0ebd Merge pull request #3854 from exviva/validates_associated_marked_for_destruction
Do not validate associated records marked for destruction
2011-12-04 15:57:13 -08:00
Olek Janiszewski
a8134aceb3 Do not validate associated records marked for destruction
The main reason for this change is to fix a bug where
`validates_associated` would prevent `accepts_nested_attributes_for`
with `allow_destroy: true` from destroying invalid associated records.
2011-12-05 00:19:21 +01:00
Jon Leighton
4ded0dd2de Merge pull request #3851 from ebeigarts/fix_sequence_name
Fix sequence name with abstract classes.
2011-12-04 15:19:17 -08:00
Xavier Noria
4e74bd194b moves some auto explain logic to the subscriber [José Valim & Xavier Noria] 2011-12-04 13:53:26 -08:00
Xavier Noria
7f3ce35e19 simplifies ActiveRecord::ExplainSubscriber [José Valim & Xavier Noria] 2011-12-04 13:27:03 -08:00
Xavier Noria
d59bfeb119 Merge branch 'explain' 2011-12-04 11:55:53 -08:00
Xavier Noria
cfeac38e2b implements a much faster auto EXPLAIN, closes #3843 [José Valim & Xavier Noria]
This commit vastly reduces the impact of auto
explain logging when enabled, while keeping
a negligible cost when disabled.

The first implementation was based on the idea
of subscribing to "sql.active_record" when
needed, and unsubscribing once done. This is
the idea behind AR::Relation#explain. Subscribe,
collect, unsubscribe.

But with the current implementation of notifications
unsubscribing is costly, because it wipes an internal
cache and that puts a penalty on the next event.

So we are switching to an approach where a long-running
subscriber is listening. Instead of collecting the
queries with a closure in a dedicated subscriber, now
we setup a thread local.

If the feature is disabled by setting the threshold
to nil, the subscriber will call a method that does
nothing. That's totally cheap.
2011-12-04 11:52:12 -08:00
Edgars Beigarts
82ae5c40ea Fix sequence name with abstract classes. 2011-12-04 20:10:14 +02:00
Carlos Antonio da Silva
4e836e4de9 Refactor readonly attributes conditional 2011-12-04 09:21:34 -02:00
Arun Agrawal
ac4763f5c0 SQlite3 Bump 2011-12-04 10:27:44 +05:30
Jon Leighton
9c172b2931 Fix #3837.
We also need to time zone convert time zone aware attributes when
accessed via read_attribute, not only when via direct access.
2011-12-03 16:46:46 +00:00