903946c78a
Colorize is a gem licensed under the GPLv2, so we can’t use it in GitLab without relicensing GitLab under the terms of the GPL. Rainbow is licensed under the MIT license and does the exact same thing as Colorize, so Rainbow was added in place of Colorize. The syntax is slightly different for Rainbow vs. Colorize, and was updated in accordance. The gem is still a dependency of Spinach, so it’s included in the development/test environments, but won’t be packaged with the actual product, and therefore doesn’t require we relicense the product. An attempt at relicensing Colorize was made, but didn’t succeed as the library owner never responded. Rainbow library: https://github.com/sickill/rainbow Relevant issue regarding licensing in GitLab's gems: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3775
50 lines
1.8 KiB
Ruby
50 lines
1.8 KiB
Ruby
namespace :gitlab do
|
|
namespace :db do
|
|
desc 'GitLab | Manually insert schema migration version'
|
|
task :mark_migration_complete, [:version] => :environment do |_, args|
|
|
unless args[:version]
|
|
puts "Must specify a migration version as an argument".color(:red)
|
|
exit 1
|
|
end
|
|
|
|
version = args[:version].to_i
|
|
if version == 0
|
|
puts "Version '#{args[:version]}' must be a non-zero integer".color(:red)
|
|
exit 1
|
|
end
|
|
|
|
sql = "INSERT INTO schema_migrations (version) VALUES (#{version})"
|
|
begin
|
|
ActiveRecord::Base.connection.execute(sql)
|
|
puts "Successfully marked '#{version}' as complete".color(:green)
|
|
rescue ActiveRecord::RecordNotUnique
|
|
puts "Migration version '#{version}' is already marked complete".color(:yellow)
|
|
end
|
|
end
|
|
|
|
desc 'Drop all tables'
|
|
task :drop_tables => :environment do
|
|
connection = ActiveRecord::Base.connection
|
|
tables = connection.tables
|
|
tables.delete 'schema_migrations'
|
|
# Truncate schema_migrations to ensure migrations re-run
|
|
connection.execute('TRUNCATE schema_migrations')
|
|
|
|
# Drop tables with cascade to avoid dependent table errors
|
|
# PG: http://www.postgresql.org/docs/current/static/ddl-depend.html
|
|
# MySQL: http://dev.mysql.com/doc/refman/5.7/en/drop-table.html
|
|
# Add `IF EXISTS` because cascade could have already deleted a table.
|
|
tables.each { |t| connection.execute("DROP TABLE IF EXISTS #{t} CASCADE") }
|
|
end
|
|
|
|
desc 'Configures the database by running migrate, or by loading the schema and seeding if needed'
|
|
task configure: :environment do
|
|
if ActiveRecord::Base.connection.tables.any?
|
|
Rake::Task['db:migrate'].invoke
|
|
else
|
|
Rake::Task['db:schema:load'].invoke
|
|
Rake::Task['db:seed_fu'].invoke
|
|
end
|
|
end
|
|
end
|
|
end
|