Skip to content

Commit

Permalink
make project name unique
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Mar 12, 2024
1 parent e1636d3 commit 3c01f6a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# Indexes
#
# index_projects_on_customer_id (customer_id)
# index_projects_on_name (name) UNIQUE
# index_projects_on_slug (slug) UNIQUE
#
# Foreign Keys
Expand All @@ -35,7 +36,7 @@ class Project < ApplicationRecord
has_many :issues, dependent: :destroy
has_many :statement_of_works, dependent: :destroy

validates :name, presence: true
validates :name, presence: true, uniqueness: { case_sensitive: false }
validates :billable, inclusion: { in: [true, false] }
validates :slack_channel, presence: true

Expand Down
1 change: 1 addition & 0 deletions bin/pull_prod_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ docker exec -it backstage-db psql -U postgres -c 'DROP DATABASE IF EXISTS backst
docker exec -it backstage-db psql -U postgres -c "CREATE DATABASE backstage_development"
docker exec -it backstage-db psql -U postgres backstage_development -c "CREATE SCHEMA IF NOT EXISTS heroku_ext AUTHORIZATION postgres"
docker exec -it backstage-db pg_restore --no-owner -U postgres -d backstage_development -1 ./app/latest.dump
docker exec -it backstage-api rails db:create
sh bin/dev
7 changes: 7 additions & 0 deletions db/migrate/20240312200929_add_name_contraint_to_project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddNameContraintToProject < ActiveRecord::Migration[7.0]
def change
add_index :projects, :name, unique: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spec/factories/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# Indexes
#
# index_projects_on_customer_id (customer_id)
# index_projects_on_name (name) UNIQUE
# index_projects_on_slug (slug) UNIQUE
#
# Foreign Keys
Expand Down
1 change: 1 addition & 0 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# Indexes
#
# index_projects_on_customer_id (customer_id)
# index_projects_on_name (name) UNIQUE
# index_projects_on_slug (slug) UNIQUE
#
# Foreign Keys
Expand Down

0 comments on commit 3c01f6a

Please sign in to comment.