Skip to content

Commit

Permalink
Add migration for TotK data
Browse files Browse the repository at this point in the history
Added doc.
  • Loading branch information
Pysis868 committed May 11, 2023
1 parent 7fd76ee commit 2782b4f
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 3 deletions.
81 changes: 81 additions & 0 deletions dev/db/migrate/20230509201500_add_tot_k_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
class AddTotKData < ActiveRecord::Migration[7.0]
def sqlFileNames
[
'1-container' ,
'2-map' ,
'3-submap' ,
'4-marker_category' ,
'5-marker'
]
end

def database
connection.instance_variable_get(:@config)[:database]
end

def up
filePathPattern = "#{__dir__}/sql/" +
File.basename(__FILE__).
sub(/\.rb$/i, '/%s.sql')

sqlFileNames.each do |sqlFileName|
sqlFile = sprintf(filePathPattern, sqlFileName);
execute File.open(sqlFile).read
end
end

def down
execute <<-SQL
DELETE FROM `marker`
WHERE `marker_category_id` BETWEEN 2100 AND 2300
;
SQL
execute <<-SQL
ALTER TABLE `marker`
AUTO_INCREMENT=12522
;
SQL

execute <<-SQL
DELETE FROM `marker_category`
WHERE `id` BETWEEN 2100 AND 2300
AND `parent_id` IS NOT NULL
;
SQL
execute <<-SQL
DELETE FROM `marker_category`
WHERE `id` BETWEEN 2100 AND 2300
AND `parent_id` IS NULL
;
SQL
execute <<-SQL
ALTER TABLE `marker_category`
AUTO_INCREMENT=1970
;
SQL

execute <<-SQL
DELETE FROM `submap`
WHERE `map_id` BETWEEN 2101 AND 2103
;
SQL

execute <<-SQL
DELETE FROM `map`
WHERE `id` BETWEEN 2101 AND 2103
;
SQL

execute <<-SQL
DELETE FROM `container`
WHERE `id` = 21
;
SQL
execute <<-SQL
ALTER TABLE `container`
AUTO_INCREMENT=20
;
SQL

end
end
36 changes: 33 additions & 3 deletions docs/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@

- Common Commands:
- Create a new migration:
- `rake db:new_migration name=(read -P 'Migration Proper Name: ')`
- `rake db:new_migration name=(read -P 'Migration Proper Name: ' | tr -d ' ')`
- Change name subshell to read `read | tr ' ' '_'` on Windows to prevent carriage return characters causing problems.
- Then edit content with your features' details.
- To apply your newest migration:
Expand Down Expand Up @@ -212,11 +212,33 @@
SQL
```
- External file:
- ```
- Code: ```
execute File.open(
'dev/db/migrate/sql/20210811040936_users_add_new_placeholders_for_new_marker_contributions.sql'
).read
```
- External files:
- Code: ```
def sqlFileNames
[
'1-container' ,
'2-map' ,
'3-submap' ,
'4-marker_category' ,
'5-marker'
]
end
```
```
filePathPattern = "#{__dir__}/sql/" +
File.basename(__FILE__).
sub(/\.rb$/i, '/%s.sql')
sqlFileNames.each do |sqlFileName|
sqlFile = sprintf(filePathPattern, sqlFileName);
execute File.open(sqlFile).read
end
```
- Multiple Queries:
- Add `.lines.each { |line| execute line if line != "\n" }` the string containing the queries separated by newlines.
- Specific Goals:
Expand All @@ -242,7 +264,8 @@
```
- Source: `dev/db/migrate/disabled/20230406031615_submap_add_tot_k_overworld_submaps.rb`
- Reverting the auto increment value:
- Code: ```
- Note: Be sure to check if the table actually has auto increment column(s).
- Code (Dynamic): ```
def database
connection.instance_variable_get(:@config)[:database]
end
Expand All @@ -265,6 +288,13 @@
;
SQL
```
- Code (Manual): ```
execute <<-SQL
ALTER TABLE `mapper`
AUTO_INCREMENT=...
;
SQL
```
- Source: `dev/db/migrate/disabled/20230406031615_submap_add_tot_k_overworld_submaps.rb`
- Names:
- Note: The RoR AR Migrations guide may recommend trying to keep migrations focused on a specific table per file.
Expand Down

0 comments on commit 2782b4f

Please sign in to comment.