From b7c5c002a238a9b06cb9620f4d83595773d2dbed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Fri, 29 Mar 2024 17:21:18 +0100 Subject: [PATCH] Once again, with better sqlite query utilizing tbl_name --- .../spec/migration_test_spec.rb | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ruby_event_store-active_record/spec/migration_test_spec.rb b/ruby_event_store-active_record/spec/migration_test_spec.rb index e4760c051a..6384eb3cca 100644 --- a/ruby_event_store-active_record/spec/migration_test_spec.rb +++ b/ruby_event_store-active_record/spec/migration_test_spec.rb @@ -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") @@ -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(