activerecord-reset-pk-sequence 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,7 +1,5 @@
1
1
  Copyright (c) 2012 Splendeo Innovación
2
2
 
3
- MIT License
4
-
5
3
  Permission is hereby granted, free of charge, to any person obtaining
6
4
  a copy of this software and associated documentation files (the
7
5
  "Software"), to deal in the Software without restriction, including
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 and Sqlite but not in MySQL up to now.
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
 
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "activerecord-reset-pk-sequence"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Activerecord::Reset::Pk::Sequence::VERSION
17
+
18
+ gem.add_development_dependency "rake"
17
19
  end
@@ -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 = "update sqlite_sequence set seq = #{new_max} where name = '#{table_name}';"
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
+
@@ -2,7 +2,7 @@ module Activerecord
2
2
  module Reset
3
3
  module Pk
4
4
  module Sequence
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
8
8
  end
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.1.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-03-27 00:00:00.000000000Z
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.6
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