diff options
author | kibigo! <marrus-sh@users.noreply.github.com> | 2017-10-11 10:43:10 -0700 |
---|---|---|
committer | kibigo! <marrus-sh@users.noreply.github.com> | 2017-10-11 10:43:10 -0700 |
commit | 8d6b9ba4946b5b159af0fbd130637a226a286796 (patch) | |
tree | 9def26711682d29338cfa1b081822029a01669eb /lib/tasks | |
parent | f0a2a6c875e9294f0ea1d4c6bc90529e41a2dc37 (diff) | |
parent | 476e79b8e340c9103352a0799e102e4aca1a5593 (diff) |
Merge upstream 2.0ish #165
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/assets.rake | 2 | ||||
-rw-r--r-- | lib/tasks/db.rake | 56 | ||||
-rw-r--r-- | lib/tasks/emojis.rake | 2 |
3 files changed, 58 insertions, 2 deletions
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 44896afc7..f60c1b9f2 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -10,7 +10,7 @@ end namespace :assets do desc 'Generate static pages' task :generate_static_pages do - render_static_page 'errors/500', layout: 'error', dest: Rails.root.join('public', '500.html') + render_static_page 'errors/500', layout: 'error', dest: Rails.root.join('public', 'assets', '500.html') end end diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 7a055bf25..32039c31d 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,5 +1,36 @@ # frozen_string_literal: true +require_relative '../mastodon/snowflake' + +def each_schema_load_environment + # If we're in development, also run this for the test environment. + # This is a somewhat hacky way to do this, so here's why: + # 1. We have to define this before we load the schema, or we won't + # have a timestamp_id function when we get to it in the schema. + # 2. db:setup calls db:schema:load_if_ruby, which calls + # db:schema:load, which we define above as having a prerequisite + # of this task. + # 3. db:schema:load ends up running + # ActiveRecord::Tasks::DatabaseTasks.load_schema_current, which + # calls a private method `each_current_configuration`, which + # explicitly also does the loading for the `test` environment + # if the current environment is `development`, so we end up + # needing to do the same, and we can't even use the same method + # to do it. + + if Rails.env == 'development' + test_conf = ActiveRecord::Base.configurations['test'] + + if test_conf['database']&.present? + ActiveRecord::Base.establish_connection(:test) + yield + ActiveRecord::Base.establish_connection(Rails.env.to_sym) + end + end + + yield +end + namespace :db do namespace :migrate do desc 'Setup the db or migrate depending on state of db' @@ -16,4 +47,29 @@ namespace :db do end end end + + # Before we load the schema, define the timestamp_id function. + # Idiomatically, we might do this in a migration, but then it + # wouldn't end up in schema.rb, so we'd need to figure out a way to + # get it in before doing db:setup as well. This is simpler, and + # ensures it's always in place. + Rake::Task['db:schema:load'].enhance ['db:define_timestamp_id'] + + # After we load the schema, make sure we have sequences for each + # table using timestamp IDs. + Rake::Task['db:schema:load'].enhance do + Rake::Task['db:ensure_id_sequences_exist'].invoke + end + + task :define_timestamp_id do + each_schema_load_environment do + Mastodon::Snowflake.define_timestamp_id + end + end + + task :ensure_id_sequences_exist do + each_schema_load_environment do + Mastodon::Snowflake.ensure_id_sequences_exist + end + end end diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake index cd5e30e96..625a6e55d 100644 --- a/lib/tasks/emojis.rake +++ b/lib/tasks/emojis.rake @@ -17,7 +17,7 @@ namespace :emojis do task :generate do source = 'http://www.unicode.org/Public/emoji/5.0/emoji-test.txt' codes = [] - dest = Rails.root.join('app', 'javascript', 'mastodon', 'emoji_map.json') + dest = Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json') puts "Downloading emojos from source... (#{source})" |