Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlyobvious committed Mar 29, 2024
1 parent b7c5c00 commit 810b61a
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions ruby_event_store-active_record/spec/migration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ module ActiveRecord
data_type = data_type_to_pg_type(ENV["DATA_TYPE"])

expect(
[
pg_schema("event_store_events"),
pg_schema("event_store_events_in_streams")
].join("\n").gsub(/\s+/, " ")
pg_schema("event_store_events").gsub(/\s+/, " ")
).to eq <<~SCHEMA.strip.gsub(/\s+/, " ")
Table "public.event_store_events"
Column | Type | Collation | Nullable | Default
Expand All @@ -47,6 +44,11 @@ module ActiveRecord
"index_event_store_events_on_valid_at" btree (valid_at)
Referenced by:
TABLE "event_store_events_in_streams" CONSTRAINT "fk_rails_c8d52b5857" FOREIGN KEY (event_id) REFERENCES event_store_events(event_id)
SCHEMA

expect(
pg_schema("event_store_events_in_streams").gsub(/\s+/, " ")
).to eq <<~SCHEMA.strip.gsub(/\s+/, " ")
Table "public.event_store_events_in_streams"
Column | Type | Collation | Nullable | Default
------------+--------------------------------+-----------+----------+-----------------------------------------------------------
Expand Down Expand Up @@ -79,12 +81,7 @@ module ActiveRecord
int_lenght = mysql_major_version == 8 ? "" : "(11)"
bigint_lenght = mysql_major_version == 8 ? "" : "(20)"

expect(
[
mysql_schema("event_store_events"),
mysql_schema("event_store_events_in_streams")
].join("\n")
).to eq <<~SCHEMA.strip
expect(mysql_schema("event_store_events")).to eq <<~SCHEMA.strip
CREATE TABLE `event_store_events` (
`id` bigint#{bigint_lenght} NOT NULL AUTO_INCREMENT,
`event_id` varchar(36) NOT NULL,
Expand All @@ -99,6 +96,11 @@ module ActiveRecord
KEY `index_event_store_events_on_created_at` (`created_at`),
KEY `index_event_store_events_on_valid_at` (`valid_at`)
) ENGINE=InnoDB DEFAULT CHARSET=#{charset}#{collation}
SCHEMA

expect(
mysql_schema("event_store_events_in_streams")
).to eq <<~SCHEMA.strip
CREATE TABLE `event_store_events_in_streams` (
`id` bigint#{bigint_lenght} NOT NULL AUTO_INCREMENT,
`stream` varchar(255) NOT NULL,
Expand All @@ -118,17 +120,17 @@ module ActiveRecord
specify "sqlite" do
skip unless ENV["DATABASE_URL"].include?("sqlite")

expect(
[
sqlite_schema("event_store_events"),
sqlite_schema("event_store_events_in_streams")
].join("\n")
).to eq <<~SCHEMA.strip
expect(sqlite_schema("event_store_events")).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")
CREATE INDEX "index_event_store_events_on_event_type" ON "event_store_events" ("event_type")
CREATE INDEX "index_event_store_events_on_created_at" ON "event_store_events" ("created_at")
CREATE INDEX "index_event_store_events_on_valid_at" ON "event_store_events" ("valid_at")
SCHEMA

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"
FOREIGN KEY ("event_id")
REFERENCES "event_store_events" ("event_id")
Expand Down

0 comments on commit 810b61a

Please sign in to comment.