Skip to content

Commit

Permalink
Fix bad migration logic
Browse files Browse the repository at this point in the history
file_hash was required in the schema but when the migration ran in production it failed because the values did not supply a file_hash.

We're just going to use application constraints instead,
  • Loading branch information
atruskie committed Dec 17, 2024
1 parent 0e244ea commit 16bf7fe
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,6 @@ Other major credits go to:
- [@Allcharles](https://github.com/Allcharles)
- [@JessieLOliver](https://github.com/JessieLOliver) for design and user experience feedback

## Licence
## License

Apache License, Version 2.0
2 changes: 1 addition & 1 deletion app/helpers/cms_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def organisation_name
def address(not_logged_in_message = '')
return not_logged_in_message unless current_user

Settings&.organisation_names&.address || '<address not configured>'
Settings.organisation_names&.address || '<address not configured>'
end

def cms_page_label
Expand Down
2 changes: 1 addition & 1 deletion app/models/audio_event_import_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# id :bigint not null, primary key
# additional_tag_ids(Additional tag ids applied for this import) :integer is an Array
# file_hash(Hash of the file contents used for uniqueness checking) :text not null
# file_hash(Hash of the file contents used for uniqueness checking) :text
# path(Path to the file on disk, relative to the analysis job item. Not used for uploaded files) :string
# created_at :datetime not null
# analysis_jobs_item_id :integer
Expand Down
3 changes: 2 additions & 1 deletion baw-server.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"binmode",
"binread",
"binstub",
"binstubs",
"birdnet",
"Boobook",
"boolify",
Expand Down Expand Up @@ -280,7 +281,7 @@
"editor.defaultFormatter": "castwide.solargraph",
//"editor.defaultFormatter": "rebornix.ruby"
},
"cSpell.enableFiletypes": [
"cSpell.enabledFiletypes": [
"ruby"
],
"editor.minimap.size": "fill",
Expand Down
9 changes: 6 additions & 3 deletions db/migrate/20240524011344_audio_event_import_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def change

t.datetime :created_at, precision: 6, null: false

t.text :file_hash, null: false, comment: 'Hash of the file contents used for uniqueness checking'
# Hudson says: because we have to migrate the data, and the previous data did not have a file_hash
# we must allow nulls here. Sticking in a fake non-null value would be a bad idea.
# Non-nullness will be enforced in the application.
t.text :file_hash, null: true, comment: 'Hash of the file contents used for uniqueness checking'
end

change_table :audio_event_imports do |t|
Expand All @@ -41,8 +44,8 @@ def change

# create a default audio_event_import_file for each audio_event_import
query = <<~SQL.squish
INSERT INTO audio_event_import_files (audio_event_import_id, created_at, path)
SELECT id, created_at, 'default' FROM audio_event_imports;
INSERT INTO audio_event_import_files (audio_event_import_id, created_at, path, file_hash)
SELECT id, created_at, 'default', null FROM audio_event_imports;
SQL

execute(query)
Expand Down
2 changes: 1 addition & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ CREATE TABLE public.audio_event_import_files (
path character varying,
additional_tag_ids integer[],
created_at timestamp(6) without time zone NOT NULL,
file_hash text NOT NULL,
file_hash text,
CONSTRAINT path_and_analysis_jobs_item CHECK ((((path IS NOT NULL) AND (analysis_jobs_item_id IS NOT NULL)) OR ((path IS NULL) AND (analysis_jobs_item_id IS NULL))))
);

Expand Down

0 comments on commit 16bf7fe

Please sign in to comment.