Skip to content

Commit

Permalink
Mysterious ways of migration DSL translation on sqlite
Browse files Browse the repository at this point in the history
AUTOINCREMENT over plain ROWID is desired for a column that participates
in ordering:
https://www.sqlite.org/autoinc.html

Added default just to match previous output, does not seem really
needed.
  • Loading branch information
mostlyobvious committed Mar 29, 2024
1 parent 96f8578 commit 3cf7a96
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]

create_table(:event_store_events_in_streams, force: false) do |t|
t.string :stream, null: false
t.integer :position, null: true
t.integer :position, null: true, default: :null
t.references :event, null: false, type: :string, limit: 36, index: true, foreign_key: { to_table: :event_store_events, primary_key: :event_id }
t.datetime :created_at, null: false, precision: 6, index: true

Expand Down
2 changes: 1 addition & 1 deletion ruby_event_store-active_record/spec/migration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module ActiveRecord
expect(
sqlite_schema("event_store_events_in_streams")
).to eq <<~SCHEMA.strip
CREATE TABLE "event_store_events_in_streams" ("id" integer NOT NULL PRIMARY KEY, "stream" varchar NOT NULL, "position" integer DEFAULT NULL, "event_id" varchar(36) NOT NULL, "created_at" datetime(6) NOT NULL, CONSTRAINT "fk_rails_c8d52b5857"
CREATE TABLE "event_store_events_in_streams" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "stream" varchar NOT NULL, "position" integer DEFAULT NULL, "event_id" varchar(36) NOT NULL, "created_at" datetime(6) NOT NULL, CONSTRAINT "fk_rails_c8d52b5857"
FOREIGN KEY ("event_id")
REFERENCES "event_store_events" ("event_id")
)
Expand Down

0 comments on commit 3cf7a96

Please sign in to comment.