fx-sequence 0.1.0 → 0.1.1
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8915009a8dd736d970d79ef2be7ce1c7bb42afdc29e362ce0a7c9905312f3720
|
4
|
+
data.tar.gz: 055d2a72ecb446d0b24ad934c03111545122cdf1f27f360cceb1ba384ee5d962
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cb072169c9679e0f493188a613cdc7ed88798958fa8ec1c4235a2fece3ca055df25cade9b90cb0193a585761487bde9a4442b318d3cd3629b6b69c735f6aabe
|
7
|
+
data.tar.gz: caea3dd9dfb206fa18df1b0dc15faeba563127c50d6085620831604278cda441c22ecce55a45eee02c4765aa7e0cb2b86abcfcc48967b855346136632a2824a9
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [0.1.1]
|
4
|
+
|
5
|
+
[0.1.1]: https://github.com/aevula/fx-sequence/compare/v0.1.0...v0.1.1
|
6
|
+
|
7
|
+
- Added rails generators
|
8
|
+
|
9
|
+
## [0.1.0]
|
10
|
+
|
11
|
+
Extension for [fx](https://github.com/aevula/fx-sequence) gem to support creation, drop and dumping to `schema.rb` PostgreSQL sequences.
|
data/lib/fx/sequence/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
Description:
|
2
|
+
Create a new database sequence for your application. This will create a new
|
3
|
+
sequence definition file and the accompanying migration.
|
4
|
+
|
5
|
+
When --no-migration is passed, skips generating a migration.
|
6
|
+
When --exact-name is passed, uses exact name without "seq" suffix.
|
7
|
+
|
8
|
+
Examples:
|
9
|
+
rails generate fx:sequence numbers
|
10
|
+
|
11
|
+
create: db/sequences/numbers_seq_v01.sql
|
12
|
+
create: db/migrate/[TIMESTAMP]_create_sequence_numbers_seq.rb
|
13
|
+
|
14
|
+
rails generate fx:sequence numbers --exact-name
|
15
|
+
|
16
|
+
create: db/sequences/numbers_v01.sql
|
17
|
+
create: db/migrate/[TIMESTAMP]_create_sequence_numbers.rb
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/active_record'
|
5
|
+
|
6
|
+
module Fx
|
7
|
+
module Generators
|
8
|
+
class SequenceGenerator < Rails::Generators::NamedBase
|
9
|
+
include Rails::Generators::Migration
|
10
|
+
|
11
|
+
source_root File.expand_path('templates', __dir__)
|
12
|
+
|
13
|
+
class_option :migration, type: :boolean
|
14
|
+
class_option :exact_name, type: :boolean, default: false, description: 'Use exact name without \'seq\' suffix'
|
15
|
+
|
16
|
+
def self.next_migration_number(dir)
|
17
|
+
::ActiveRecord::Generators::Base.next_migration_number(dir)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_sequences_directory
|
21
|
+
return if sequence_definition_path.exist?
|
22
|
+
|
23
|
+
empty_directory(sequence_definition_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_sequence_definition
|
27
|
+
if creating_new_sequence?
|
28
|
+
create_file(definition.path, default_sql_definition)
|
29
|
+
else
|
30
|
+
copy_file(previous_definition.full_path, definition.full_path)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_migration_file
|
35
|
+
return if skip_migration_creation?
|
36
|
+
|
37
|
+
migration_template('db/migrate/create_sequence.erb', "db/migrate/create_sequence_#{sequence_name}.rb")
|
38
|
+
end
|
39
|
+
|
40
|
+
no_tasks do
|
41
|
+
def previous_version
|
42
|
+
@previous_version ||= Dir.entries(sequence_definition_path)
|
43
|
+
.map { |name| extract_version(name) }
|
44
|
+
.max
|
45
|
+
end
|
46
|
+
|
47
|
+
def version
|
48
|
+
@version ||= previous_version.next
|
49
|
+
end
|
50
|
+
|
51
|
+
def activerecord_migration_class
|
52
|
+
if ActiveRecord::Migration.respond_to?(:current_version)
|
53
|
+
"ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
|
54
|
+
else
|
55
|
+
'ActiveRecord::Migration'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def formatted_name
|
60
|
+
name = singular_name.include?('.') ? "\"#{singular_name}\"" : ":#{singular_name}"
|
61
|
+
sequence_name(name)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def sequence_definition_path
|
68
|
+
@sequence_definition_path ||= Rails.root.join(*%w[db sequences])
|
69
|
+
end
|
70
|
+
|
71
|
+
def version_regex; end
|
72
|
+
|
73
|
+
def extract_version(name)
|
74
|
+
Integer(/\A#{sequence_name}_v(?<version>\d+)\.sql\z/.match(name).try(:[], 'version'), 10)
|
75
|
+
rescue ArgumentError
|
76
|
+
0
|
77
|
+
end
|
78
|
+
|
79
|
+
def creating_new_sequence?
|
80
|
+
previous_version.zero?
|
81
|
+
end
|
82
|
+
|
83
|
+
def definition
|
84
|
+
Fx::Sequence::Definition.sequence(name: sequence_name, version: version)
|
85
|
+
end
|
86
|
+
|
87
|
+
def previous_definition
|
88
|
+
Fx::Sequence::Definition.sequence(name: sequence_name, version: previous_version)
|
89
|
+
end
|
90
|
+
|
91
|
+
def skip_migration_creation?
|
92
|
+
!migration
|
93
|
+
end
|
94
|
+
|
95
|
+
def migration
|
96
|
+
options[:migration] != false
|
97
|
+
end
|
98
|
+
|
99
|
+
def default_sql_definition
|
100
|
+
<<~SQL
|
101
|
+
CREATE SEQUENCE #{sequence_name};
|
102
|
+
SQL
|
103
|
+
end
|
104
|
+
|
105
|
+
def sequence_name(name = file_name)
|
106
|
+
options[:exact_name] ? name : "#{name}_seq"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fx-sequence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@aevula"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fx
|
@@ -30,6 +30,7 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- CHANGELOG.md
|
33
34
|
- README.md
|
34
35
|
- Rakefile
|
35
36
|
- lib/fx/sequence.rb
|
@@ -43,6 +44,9 @@ files:
|
|
43
44
|
- lib/fx/sequence/sequence.rb
|
44
45
|
- lib/fx/sequence/statements.rb
|
45
46
|
- lib/fx/sequence/version.rb
|
47
|
+
- lib/generators/fx/sequence/USAGE
|
48
|
+
- lib/generators/fx/sequence/sequence_generator.rb
|
49
|
+
- lib/generators/fx/sequence/templates/db/migrate/create_sequence.erb
|
46
50
|
homepage: https://github.com/aevula/fx-sequence
|
47
51
|
licenses:
|
48
52
|
- MIT
|