server: noop in migration when there's nothing to do

This commit is contained in:
0x1eef 2024-04-27 03:51:46 -03:00
parent 897260ce83
commit ff6acde702
3 changed files with 8 additions and 0 deletions

View file

@ -2,6 +2,7 @@
Sequel.migration do
up do
next if table_exists?(:projects)
create_table(:projects) do
primary_key :id
String :name, null: false

View file

@ -2,6 +2,7 @@
Sequel.migration do
up do
next if table_exists?(:tasks)
create_table(:tasks) do |t|
primary_key :id
String :title, null: false

View file

@ -1,7 +1,13 @@
# frozen_string_literal: true
Sequel.migration do
column_exists = ->(table, column) do
schema = Twenty.connection.schema(table)
schema.find { |(key,_)| key == column }
end
up do
next if column_exists.call(:projects, :color)
default = Twenty::Mixin::Colorable.random_color
add_column :projects, :color, :string, null: false, default:
end