Skip to content

Commit

Permalink
feat: Added download_filename_type value for old data
Browse files Browse the repository at this point in the history
  • Loading branch information
rakuyoMo committed Nov 29, 2024
1 parent 9ed480f commit 6ff8cf5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Channel < ApplicationRecord
macos: 'macOS', windows: 'Windows', linux: 'Linux'
}

# 修改该变量后,记得同步修改数据库的默认值
DEFAULT_DOWNLOAD_FILENAME_TYPE = :version_datetime

enum :download_filename_type, {
Expand Down
17 changes: 15 additions & 2 deletions db/migrate/20241127143631_add_download_file_type_to_channel.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# frozen_string_literal: true

class AddDownloadFileTypeToChannel < ActiveRecord::Migration[7.1]
def change
add_column :channels, :download_filename_type, :string, null: true
def up
# Ensure this incremental update migration is idempotent
# with monolithic install migration.
return if connection.column_exists?(:channels, :download_filename_type)

add_column :channels, :download_filename_type, :string

Channel.find_each do |channel|
# 默认值取自 `Channel.DEFAULT_DOWNLOAD_FILENAME_TYPE`
channel.update!(download_filename_type: 'version_datetime') if channel.download_filename_type.nil?
end
end

def down
remove_column :channels, :download_filename_type
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
t.string "git_url"
t.string "password"
t.string "key"
t.string "download_filename_type", null: false
t.string "download_filename_type"
t.index ["bundle_id"], name: "index_channels_on_bundle_id"
t.index ["device_type"], name: "index_channels_on_device_type"
t.index ["name"], name: "index_channels_on_name"
Expand Down

0 comments on commit 6ff8cf5

Please sign in to comment.