Skip to content

Fix regex to correctly match end of CREATE TABLE statements in schema… - #285

Open
Br3nda wants to merge 2 commits into
mainfrom
fix/end-line
Open

Br3nda wants to merge 2 commits into
mainfrom
fix/end-line

Conversation

@Br3nda

@Br3nda Br3nda commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

What and why

Fixes script for copying data to test, to cope with ; in comments

Type of change

  • Bug fix

Assisted By: My brain

@Br3nda
Br3nda requested a review from a team as a code owner October 21, 2026 19:44

@ianheggie-oaf ianheggie-oaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works against the current twfy schema. CI only passed on the old regex because spec/fixtures/schema.sql predates the proof column on hansard (twfy af5b87be), so CI never sees a ; inside a comment.

Could you refresh the fixture by re-copying db/schema.sql from an up-to-date twfy checkout? It's the schema CI always uses, and the proof column's comment turns it into a regression test for this fix. The other difference is the new email_suppressions table, which is harmless.

Assisted-by: Claude Code:claude-opus-5-5

sql = File.read(schema_file)
TABLES_NEEDED.map do |table|
sql[/CREATE TABLE `#{table}`.*?;/m] or raise "Table '#{table}' not found in schema.sql"
sql[/CREATE TABLE `#{table}`.*?;$/m] or raise "Table '#{table}' not found in schema.sql"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sql[/CREATE TABLE `#{table}`.*?;$/m] or raise "Table '#{table}' not found in schema.sql"
sql[/CREATE TABLE `#{table}`.*?;\r?$/m] or raise "Table '#{table}' not found in schema.sql"

So a checkout with Windows line endings still matches, rather than running on into the next table.

@ianheggie-oaf ianheggie-oaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, but please update spec/fixtures/schema.sql so the CI tests test it, and add the suggested change to regexp in case someone updated schema with MS windows line endings in the future - a simple fix whilst we are here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants