activerecord-reset-pk-sequence 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# active-reset-pk-sequence
|
2
2
|
|
3
|
-
This gem allows resetting the id of an AR table to 0. It is useful after a delete_all command. It works in Postgres
|
3
|
+
This gem allows resetting the id of an AR table to 0. It is useful after a delete_all command. It works in Postgres, Sqlite and MySQL up to now.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -6,7 +6,11 @@ module ActiveRecord
|
|
6
6
|
case ActiveRecord::Base.connection.adapter_name
|
7
7
|
when 'SQLite'
|
8
8
|
new_max = maximum(primary_key) || 0
|
9
|
-
update_seq_sql = "
|
9
|
+
update_seq_sql = "UPDATE sqlite_sequence SET seq = #{new_max} WHERE name = '#{table_name}';"
|
10
|
+
ActiveRecord::Base.connection.execute(update_seq_sql)
|
11
|
+
when 'Mysql'
|
12
|
+
new_max = maximum(primary_key) + 1 || 1
|
13
|
+
update_seq_sql = "ALTER TABLE '#{table_name}' AUTO_INCREMENT = #{new_max};"
|
10
14
|
ActiveRecord::Base.connection.execute(update_seq_sql)
|
11
15
|
when 'PostgreSQL'
|
12
16
|
ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
|
@@ -16,3 +20,4 @@ module ActiveRecord
|
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
23
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-reset-pk-sequence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: Id of an AR table cleaner. Works for Postgres and Sqlite.
|
15
31
|
email:
|
16
32
|
- support@splendeo.es
|
@@ -46,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
62
|
version: '0'
|
47
63
|
requirements: []
|
48
64
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.8.
|
65
|
+
rubygems_version: 1.8.24
|
50
66
|
signing_key:
|
51
67
|
specification_version: 3
|
52
68
|
summary: Allows resetting the id of an AR table to 0. Useful after a delete_all. Works
|