demo_mode 3.8.1 → 3.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e73fd7fddd766bef9d1545a62dc2ddd66afc0b8b9c54520eaaf0a565133b475
4
- data.tar.gz: a4738c449db124a9a0bcd78f75ef4f5d3a0f5de70bc3d841ef42b8e602f3d971
3
+ metadata.gz: 8a42266ca5bccc56fab0ad7e1af18130df9faddec788050ea4b82f54649aef2a
4
+ data.tar.gz: '088b56e46034f90fa4c068143c82b6f7085c87479c016ba1c1da95cac16e2f6b'
5
5
  SHA512:
6
- metadata.gz: 74f400f23e3c529a3b928861a6870ac5b39e234cd0fa69174bd88176bb6ac416518a46b390d78dd4a671958b164dd2aa4fabc95a557c051b6835e70f4a555d2d
7
- data.tar.gz: 06d3c2e5dd2dd757b11c3195124ec237839b56f68f46b693b8cde88c5d7875fdf21bd19333e732ca9c0cd49e8848c112cf9d95e8fa5abba6b57e09c09dc08fd9
6
+ metadata.gz: e758514dadb1008de64d66c94d03cfe63b44968260d1b2a254a8ba1d6079fac0a09a91beb1e25c93f23ff8444163fffb28505c21ad59d8d0543ed54e3d476e0f
7
+ data.tar.gz: f524ea55e3b99a6d4082e9e33155fa1690742db5bd5ea69460887ed4db0111b6e2ffea3680f99a56baec06609eab17351a242816967be8352e51263788c8844d
@@ -13,7 +13,9 @@ class CleverSequence
13
13
  @attribute = attribute
14
14
 
15
15
  super(
16
- "Sequence '#{sequence_name}' not found for #{klass.name}##{attribute}. "
16
+ "Sequence '#{sequence_name}' not found for #{klass.name}##{attribute}. " \
17
+ "Generate a migration to create it with: " \
18
+ "bin/rails generate demo_mode:clever_sequence #{klass.name} #{attribute}"
17
19
  )
18
20
  end
19
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DemoMode
4
- VERSION = '3.8.1'
4
+ VERSION = '3.9.0'
5
5
  end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+ require 'rails/generators/active_record'
5
+ require 'demo_mode/clever_sequence/postgres_backend'
6
+
7
+ module DemoMode
8
+ # Generates a migration that creates the PostgreSQL sequence backing a
9
+ # CleverSequence, in response to
10
+ # CleverSequence::PostgresBackend::SequenceNotFoundError.
11
+ #
12
+ # bundle exec rails generate demo_mode:clever_sequence Widget integer_column
13
+ #
14
+ # By default the migration is written to the app's primary db/migrate path.
15
+ # Use --database to target a connection's migrations_paths (from
16
+ # config/database.yml), or --migrations-path to write to an explicit
17
+ # directory (e.g. an engine's migrate dir in a monorepo).
18
+ class CleverSequenceGenerator < Rails::Generators::Base
19
+ include ActiveRecord::Generators::Migration
20
+
21
+ desc 'Creates a migration that creates the PostgreSQL sequence backing a CleverSequence.'
22
+ source_root File.expand_path('../templates', __dir__)
23
+
24
+ argument :model, type: :string, banner: 'Model'
25
+ argument :attribute, type: :string, banner: 'attribute'
26
+
27
+ class_option :database, type: :string, aliases: %w(--db),
28
+ desc: "The database whose migrations_paths to use (from config/database.yml)."
29
+ class_option :migrations_path, type: :string,
30
+ desc: 'Explicit directory to write the migration into (overrides --database and the default).'
31
+
32
+ def create_sequence_migration
33
+ migration_template(
34
+ 'clever_sequence_migration.rb.tt',
35
+ File.join(target_migrate_path, "create_clever_sequence_#{sequence_name}.rb"),
36
+ )
37
+ end
38
+
39
+ no_tasks do
40
+ def sequence_name
41
+ CleverSequence::PostgresBackend.sequence_name(model_class, attribute)
42
+ end
43
+
44
+ def migration_class_name
45
+ "CreateCleverSequence#{sequence_name.camelize}"
46
+ end
47
+
48
+ def migration_version
49
+ "[#{ActiveRecord::Migration.current_version}]"
50
+ end
51
+
52
+ def table_name
53
+ model_class.table_name
54
+ end
55
+
56
+ # The DB column the sequence advances past. Resolves attribute aliases
57
+ # the same way CleverSequence::PostgresBackend does.
58
+ def column_name
59
+ model_class.attribute_aliases.fetch(attribute.to_s, attribute.to_s)
60
+ end
61
+
62
+ # Whether the backing column is an integer, so seeding the sequence
63
+ # past MAX(column) is meaningful. Other columns (e.g. a string column)
64
+ # are created at their default start; runtime adjustment handles
65
+ # advancing them.
66
+ def integer_column?
67
+ model_class.columns_hash[column_name]&.type == :integer
68
+ end
69
+
70
+ private
71
+
72
+ # Where the migration is written. An explicit --migrations-path wins;
73
+ # otherwise fall back to Rails' resolution (db_migrate_path), which
74
+ # honors --database via config/database.yml's migrations_paths.
75
+ def target_migrate_path
76
+ options[:migrations_path].presence || db_migrate_path
77
+ end
78
+
79
+ def model_class
80
+ @model_class ||= model.camelize.constantize
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Creates the PostgreSQL sequence backing CleverSequence for
4
+ # <%= model %>#<%= attribute %> (sequence: <%= sequence_name %>).
5
+ #
6
+ # Generated in response to
7
+ # CleverSequence::PostgresBackend::SequenceNotFoundError.
8
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
9
+ def up
10
+ execute("CREATE SEQUENCE IF NOT EXISTS <%= sequence_name %>")
11
+ <% if integer_column? -%>
12
+
13
+ # Advance the sequence past any existing data so demo-generated records
14
+ # don't collide with real rows. Mirrors the runtime adjustment in
15
+ # CleverSequence::PostgresBackend#adjust_sequence_if_needed.
16
+ max_value = select_value(
17
+ "SELECT COALESCE(MAX(<%= column_name %>), 0) FROM <%= table_name %>",
18
+ ).to_i
19
+
20
+ execute("SELECT setval('<%= sequence_name %>', #{max_value})") if max_value >= 1
21
+ <% end -%>
22
+ end
23
+
24
+ def down
25
+ execute("DROP SEQUENCE IF EXISTS <%= sequence_name %>")
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demo_mode
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.1
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Griffith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-13 00:00:00.000000000 Z
11
+ date: 2026-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -369,7 +369,9 @@ files:
369
369
  - lib/demo_mode/persona.rb
370
370
  - lib/demo_mode/tasks.rb
371
371
  - lib/demo_mode/version.rb
372
+ - lib/generators/demo_mode/clever_sequence_generator.rb
372
373
  - lib/generators/demo_mode/install_generator.rb
374
+ - lib/generators/templates/clever_sequence_migration.rb.tt
373
375
  - lib/generators/templates/initializer.rb
374
376
  - lib/generators/templates/sample_persona.rb
375
377
  - public/demo_mode/assets/demo_mode.css