database_cleaner 1.99.0 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_cleaner.rb +1 -47
- metadata +14 -484
- data/CONTRIBUTE.markdown +0 -27
- data/Gemfile.lock +0 -324
- data/History.rdoc +0 -514
- data/LICENSE +0 -20
- data/README.markdown +0 -389
- data/Rakefile +0 -44
- data/TODO +0 -3
- data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +0 -1
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +0 -6
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/base.rb +0 -101
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/deletion.rb +0 -108
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/transaction.rb +0 -59
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/truncation.rb +0 -288
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +0 -5
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +0 -1
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +0 -13
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/base.rb +0 -7
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/truncation.rb +0 -28
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +0 -5
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +0 -1
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +0 -6
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/base.rb +0 -25
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/transaction.rb +0 -28
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/truncation.rb +0 -173
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +0 -5
- data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +0 -1
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +0 -11
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/base.rb +0 -16
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/deletion.rb +0 -8
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation.rb +0 -74
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +0 -5
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +0 -1
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +0 -5
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/base.rb +0 -24
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +0 -35
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +0 -5
- data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +0 -1
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +0 -11
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/base.rb +0 -20
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/deletion.rb +0 -10
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +0 -26
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb +0 -38
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +0 -65
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/truncation.rb +0 -49
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +0 -5
- data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +0 -1
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +0 -12
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/base.rb +0 -39
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation.rb +0 -9
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation_base.rb +0 -44
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +0 -5
- data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +0 -1
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +0 -7
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/base.rb +0 -66
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/deletion.rb +0 -16
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/transaction.rb +0 -35
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/truncation.rb +0 -9
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +0 -5
- data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +0 -1
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +0 -12
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +0 -24
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +0 -5
- data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +0 -1
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +0 -5
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb +0 -45
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/deletion.rb +0 -9
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/truncation.rb +0 -26
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +0 -5
- data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +0 -1
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +0 -6
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/base.rb +0 -26
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/deletion.rb +0 -47
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb +0 -40
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/truncation.rb +0 -79
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +0 -5
- data/cucumber.yml +0 -1
- data/lib/database_cleaner/base.rb +0 -169
- data/lib/database_cleaner/configuration.rb +0 -136
- data/lib/database_cleaner/cucumber.rb +0 -3
- data/lib/database_cleaner/deprecation.rb +0 -26
- data/lib/database_cleaner/generic/base.rb +0 -29
- data/lib/database_cleaner/generic/transaction.rb +0 -11
- data/lib/database_cleaner/generic/truncation.rb +0 -40
- data/lib/database_cleaner/null_strategy.rb +0 -20
- data/lib/database_cleaner/orm_autodetector.rb +0 -41
- data/lib/database_cleaner/safeguard.rb +0 -107
- data/lib/database_cleaner/spec.rb +0 -2
- data/lib/database_cleaner/spec/database_helper.rb +0 -82
- data/lib/database_cleaner/spec/shared_examples.rb +0 -15
- data/lib/database_cleaner/version.rb +0 -3
@@ -1 +0,0 @@
|
|
1
|
-
require "database_cleaner/neo4j"
|
@@ -1,7 +0,0 @@
|
|
1
|
-
require "database_cleaner/neo4j/version"
|
2
|
-
require "database_cleaner"
|
3
|
-
require "database_cleaner/neo4j/transaction"
|
4
|
-
require "database_cleaner/neo4j/truncation"
|
5
|
-
require "database_cleaner/neo4j/deletion"
|
6
|
-
|
7
|
-
DatabaseCleaner.deprecate "Due to lack of maintenance, the Neo4j adapter for DatabaseCleaner is deprecated, and will be removed in v2.0 with no replacement. Contact us if you are interested in resurrecting this adapter!"
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'database_cleaner/generic/base'
|
2
|
-
module DatabaseCleaner
|
3
|
-
module Neo4j
|
4
|
-
def self.available_strategies
|
5
|
-
%w[transaction truncation deletion]
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.default_strategy
|
9
|
-
:transaction
|
10
|
-
end
|
11
|
-
|
12
|
-
module Base
|
13
|
-
include ::DatabaseCleaner::Generic::Base
|
14
|
-
|
15
|
-
def db=(desired_db)
|
16
|
-
@db = desired_db == :default ? nil : desired_db
|
17
|
-
end
|
18
|
-
|
19
|
-
def db
|
20
|
-
@db ||= nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def start
|
24
|
-
if db_type == :embedded_db and not session.running?
|
25
|
-
session.start
|
26
|
-
else
|
27
|
-
session
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def database
|
32
|
-
db && default_db.merge(db) || default_db
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def default_db
|
38
|
-
{:type => default_db_type, :path => default_db_path}
|
39
|
-
end
|
40
|
-
|
41
|
-
def default_db_type
|
42
|
-
:server_db
|
43
|
-
end
|
44
|
-
|
45
|
-
def default_db_path(type = default_db_type)
|
46
|
-
type == :server_db ? 'http://localhost:7475/' : './db/test'
|
47
|
-
end
|
48
|
-
|
49
|
-
def db_type
|
50
|
-
database[:type]
|
51
|
-
end
|
52
|
-
|
53
|
-
def db_path
|
54
|
-
database[:path]
|
55
|
-
end
|
56
|
-
|
57
|
-
def db_params
|
58
|
-
database.reject!{|key, value| [:type, :path].include? key }
|
59
|
-
end
|
60
|
-
|
61
|
-
def session
|
62
|
-
@session ||= ::Neo4j::Session.open(db_type, db_path, db_params)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'database_cleaner/neo4j/base'
|
2
|
-
require 'neo4j-core'
|
3
|
-
|
4
|
-
module DatabaseCleaner
|
5
|
-
module Neo4j
|
6
|
-
class Deletion
|
7
|
-
include ::DatabaseCleaner::Neo4j::Base
|
8
|
-
|
9
|
-
def clean
|
10
|
-
::Neo4j::Transaction.run do
|
11
|
-
session._query('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'database_cleaner/neo4j/base'
|
2
|
-
require 'database_cleaner/generic/transaction'
|
3
|
-
require 'neo4j-core'
|
4
|
-
|
5
|
-
module DatabaseCleaner
|
6
|
-
module Neo4j
|
7
|
-
class Transaction
|
8
|
-
include ::DatabaseCleaner::Generic::Transaction
|
9
|
-
include ::DatabaseCleaner::Neo4j::Base
|
10
|
-
|
11
|
-
attr_accessor :tx
|
12
|
-
|
13
|
-
def start
|
14
|
-
super
|
15
|
-
rollback
|
16
|
-
self.tx = ::Neo4j::Transaction.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def clean
|
20
|
-
rollback
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def rollback
|
26
|
-
if tx
|
27
|
-
tx.failure
|
28
|
-
tx.close
|
29
|
-
end
|
30
|
-
ensure
|
31
|
-
self.tx = nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require "database_cleaner/ohm"
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require "database_cleaner/ohm/version"
|
2
|
-
require "database_cleaner"
|
3
|
-
require "database_cleaner/ohm/truncation"
|
4
|
-
|
5
|
-
DatabaseCleaner.deprecate "The Ohm adapter for DatabaseCleaner is deprecated, and will be removed in v2.0. Please use the Redis adapter instead."
|
6
|
-
|
7
|
-
module DatabaseCleaner::Ohm
|
8
|
-
def self.default_strategy
|
9
|
-
:truncation
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
@@ -1,24 +0,0 @@
|
|
1
|
-
begin # when database_cleaner-ohm is loaded as a gem
|
2
|
-
require 'database_cleaner/redis/truncation'
|
3
|
-
rescue LoadError # when database_cleaner is loaded as a gem
|
4
|
-
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../../../../adapters/database_cleaner-redis/lib")
|
5
|
-
require 'database_cleaner/redis/truncation'
|
6
|
-
end
|
7
|
-
|
8
|
-
module DatabaseCleaner
|
9
|
-
module Ohm
|
10
|
-
def self.available_strategies
|
11
|
-
%w(truncation)
|
12
|
-
end
|
13
|
-
|
14
|
-
class Truncation < ::DatabaseCleaner::Redis::Truncation
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def default_redis
|
19
|
-
::Ohm.redis
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require "database_cleaner/redis"
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'database_cleaner/generic/base'
|
2
|
-
require 'database_cleaner/deprecation'
|
3
|
-
|
4
|
-
module DatabaseCleaner
|
5
|
-
module Redis
|
6
|
-
def self.available_strategies
|
7
|
-
%w{truncation deletion}
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.default_strategy
|
11
|
-
:truncation
|
12
|
-
end
|
13
|
-
|
14
|
-
module Base
|
15
|
-
include ::DatabaseCleaner::Generic::Base
|
16
|
-
|
17
|
-
def db=(desired_db)
|
18
|
-
@db = desired_db
|
19
|
-
end
|
20
|
-
|
21
|
-
def db
|
22
|
-
@db ||= :default
|
23
|
-
end
|
24
|
-
|
25
|
-
def url
|
26
|
-
DatabaseCleaner.deprecate "The redis deletion strategy's #url method is deprecated. It will be removed in database_cleaner-redis 2.0 in favor of #db."
|
27
|
-
db
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def connection
|
33
|
-
@connection ||= begin
|
34
|
-
if url == :default
|
35
|
-
::Redis.new
|
36
|
-
elsif db.is_a?(::Redis) # pass directly the connection
|
37
|
-
db
|
38
|
-
else
|
39
|
-
::Redis.new(:url => db)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'database_cleaner/redis/base'
|
2
|
-
require 'database_cleaner/generic/truncation'
|
3
|
-
|
4
|
-
module DatabaseCleaner
|
5
|
-
module Redis
|
6
|
-
class Truncation
|
7
|
-
include ::DatabaseCleaner::Redis::Base
|
8
|
-
include ::DatabaseCleaner::Generic::Truncation
|
9
|
-
|
10
|
-
def clean
|
11
|
-
if @only
|
12
|
-
@only.each do |term|
|
13
|
-
connection.keys(term).each { |k| connection.del k }
|
14
|
-
end
|
15
|
-
elsif @tables_to_exclude
|
16
|
-
keys_except = []
|
17
|
-
@tables_to_exclude.each { |term| keys_except += connection.keys(term) }
|
18
|
-
connection.keys.each { |k| connection.del(k) unless keys_except.include?(k) }
|
19
|
-
else
|
20
|
-
connection.flushdb
|
21
|
-
end
|
22
|
-
connection.quit unless db == :default
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require "database_cleaner/sequel"
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'database_cleaner/generic/base'
|
2
|
-
module DatabaseCleaner
|
3
|
-
module Sequel
|
4
|
-
def self.available_strategies
|
5
|
-
%w(truncation transaction deletion)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.default_strategy
|
9
|
-
:transaction
|
10
|
-
end
|
11
|
-
|
12
|
-
module Base
|
13
|
-
include ::DatabaseCleaner::Generic::Base
|
14
|
-
|
15
|
-
def db=(desired_db)
|
16
|
-
@db = desired_db
|
17
|
-
end
|
18
|
-
|
19
|
-
def db
|
20
|
-
return @db if @db && @db != :default
|
21
|
-
raise "As you have more than one active sequel database you have to specify the one to use manually!" if ::Sequel::DATABASES.count > 1
|
22
|
-
::Sequel::DATABASES.first || :default
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'database_cleaner/sequel/base'
|
2
|
-
require 'database_cleaner/generic/truncation'
|
3
|
-
require 'database_cleaner/sequel/truncation'
|
4
|
-
|
5
|
-
module DatabaseCleaner::Sequel
|
6
|
-
class Deletion < Truncation
|
7
|
-
def disable_referential_integrity(tables)
|
8
|
-
case db.database_type
|
9
|
-
when :postgres
|
10
|
-
db.run('SET CONSTRAINTS ALL DEFERRED')
|
11
|
-
tables_to_truncate(db).each do |table|
|
12
|
-
db.run("ALTER TABLE \"#{table}\" DISABLE TRIGGER ALL")
|
13
|
-
end
|
14
|
-
when :mysql
|
15
|
-
old = db.fetch('SELECT @@FOREIGN_KEY_CHECKS').first[:@@FOREIGN_KEY_CHECKS]
|
16
|
-
db.run('SET FOREIGN_KEY_CHECKS = 0')
|
17
|
-
end
|
18
|
-
yield
|
19
|
-
ensure
|
20
|
-
case db.database_type
|
21
|
-
when :postgres
|
22
|
-
tables.each do |table|
|
23
|
-
db.run("ALTER TABLE \"#{table}\" ENABLE TRIGGER ALL")
|
24
|
-
end
|
25
|
-
when :mysql
|
26
|
-
db.run("SET FOREIGN_KEY_CHECKS = #{old}")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def delete_tables(db, tables)
|
31
|
-
tables.each do |table|
|
32
|
-
db[table.to_sym].delete
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def clean
|
37
|
-
return unless dirty?
|
38
|
-
|
39
|
-
tables = tables_to_truncate(db)
|
40
|
-
db.transaction do
|
41
|
-
disable_referential_integrity(tables) do
|
42
|
-
delete_tables(db, tables)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'database_cleaner/sequel/base'
|
2
|
-
module DatabaseCleaner
|
3
|
-
module Sequel
|
4
|
-
class Transaction
|
5
|
-
include ::DatabaseCleaner::Sequel::Base
|
6
|
-
|
7
|
-
def self.check_fiber_brokenness
|
8
|
-
if !@checked_fiber_brokenness && Fiber.new { Thread.current }.resume != Thread.current
|
9
|
-
raise RuntimeError, "This ruby engine's Fibers are not compatible with Sequel's connection pool. " +
|
10
|
-
"To work around this, please use DatabaseCleaner.cleaning with a block instead of " +
|
11
|
-
"DatabaseCleaner.start and DatabaseCleaner.clean"
|
12
|
-
end
|
13
|
-
@checked_fiber_brokenness = true
|
14
|
-
end
|
15
|
-
|
16
|
-
def start
|
17
|
-
self.class.check_fiber_brokenness
|
18
|
-
|
19
|
-
@fibers ||= []
|
20
|
-
db = self.db
|
21
|
-
f = Fiber.new do
|
22
|
-
db.transaction(:rollback => :always, :savepoint => true) do
|
23
|
-
Fiber.yield
|
24
|
-
end
|
25
|
-
end
|
26
|
-
f.resume
|
27
|
-
@fibers << f
|
28
|
-
end
|
29
|
-
|
30
|
-
def clean
|
31
|
-
f = @fibers.pop
|
32
|
-
f.resume
|
33
|
-
end
|
34
|
-
|
35
|
-
def cleaning
|
36
|
-
self.db.transaction(:rollback => :always, :savepoint => true) { yield }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'database_cleaner/generic/truncation'
|
2
|
-
require 'database_cleaner/sequel/base'
|
3
|
-
|
4
|
-
module DatabaseCleaner
|
5
|
-
module Sequel
|
6
|
-
class Truncation
|
7
|
-
include ::DatabaseCleaner::Sequel::Base
|
8
|
-
include ::DatabaseCleaner::Generic::Truncation
|
9
|
-
|
10
|
-
def start
|
11
|
-
@last_txid = txid
|
12
|
-
end
|
13
|
-
|
14
|
-
def clean
|
15
|
-
return unless dirty?
|
16
|
-
|
17
|
-
tables = tables_to_truncate(db)
|
18
|
-
|
19
|
-
# Count rows before truncating
|
20
|
-
if pre_count?
|
21
|
-
tables = pre_count_tables(tables)
|
22
|
-
end
|
23
|
-
|
24
|
-
case db.database_type
|
25
|
-
when :postgres
|
26
|
-
# PostgreSQL requires all tables with FKs to be truncates in the same command, or have the CASCADE keyword
|
27
|
-
# appended. Bulk truncation without CASCADE is:
|
28
|
-
# * Safer. Tables outside of tables_to_truncate won't be affected.
|
29
|
-
# * Faster. Less roundtrips to the db.
|
30
|
-
unless tables.empty?
|
31
|
-
tables_sql = tables.map { |t| %("#{t}") }.join(',')
|
32
|
-
db.run "TRUNCATE TABLE #{tables_sql} RESTART IDENTITY;"
|
33
|
-
end
|
34
|
-
else
|
35
|
-
truncate_tables(db, tables)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def pre_count_tables tables
|
42
|
-
tables.reject { |table| db[table.to_sym].count == 0 }
|
43
|
-
end
|
44
|
-
|
45
|
-
def truncate_tables(db, tables)
|
46
|
-
tables.each do |table|
|
47
|
-
db[table.to_sym].truncate
|
48
|
-
if db.database_type == :sqlite && db.table_exists?(:sqlite_sequence)
|
49
|
-
db[:sqlite_sequence].where(name: table).delete
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def dirty?
|
55
|
-
@last_txid != txid || @last_txid.nil?
|
56
|
-
end
|
57
|
-
|
58
|
-
def txid
|
59
|
-
case db.database_type
|
60
|
-
when :postgres
|
61
|
-
db.fetch('SELECT txid_snapshot_xmax(txid_current_snapshot()) AS txid').first[:txid]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def tables_to_truncate(db)
|
66
|
-
(@only || db.tables.map(&:to_s)) - @tables_to_exclude
|
67
|
-
end
|
68
|
-
|
69
|
-
# overwritten
|
70
|
-
def migration_storage_names
|
71
|
-
%w(schema_info schema_migrations)
|
72
|
-
end
|
73
|
-
|
74
|
-
def pre_count?
|
75
|
-
@pre_count == true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|