Skip to content

Commit

Permalink
Once again, with better sqlite query utilizing tbl_name
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlyobvious committed Mar 29, 2024
1 parent 9ca07fb commit b7c5c00
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ruby_event_store-active_record/spec/migration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,10 @@ module ActiveRecord
skip unless ENV["DATABASE_URL"].include?("sqlite")

expect(
::ActiveRecord::Base
.connection
.execute(<<~SQL)
SELECT sql
FROM sqlite_schema
WHERE NAME LIKE '%event_store_events%'
SQL
.map { |x| x["sql"] }
.join("\n")
[
sqlite_schema("event_store_events"),
sqlite_schema("event_store_events_in_streams")
].join("\n")
).to eq <<~SCHEMA.strip
CREATE TABLE "event_store_events" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "event_id" varchar(36) NOT NULL, "event_type" varchar NOT NULL, "metadata" blob, "data" blob NOT NULL, "created_at" datetime(6) NOT NULL, "valid_at" datetime(6))
CREATE UNIQUE INDEX "index_event_store_events_on_event_id" ON "event_store_events" ("event_id")
Expand Down Expand Up @@ -157,6 +152,18 @@ def data_type_to_mysql_type(data_type)
{ "binary" => "blob", "json" => "json" }.fetch(data_type)
end

def sqlite_schema(name)
::ActiveRecord::Base
.connection
.execute(<<~SQL)
SELECT sql
FROM sqlite_schema
WHERE tbl_name = '#{name}'
SQL
.map { |x| x["sql"] }
.join("\n")
end

def pg_schema(table_name)
IO
.popen(
Expand Down

0 comments on commit b7c5c00

Please sign in to comment.