Skip to content

Commit df54086

Browse files
authored
change topic uid column to string type (#111)
2 parents d92da44 + a0e7494 commit df54086

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

app/models/topic.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# description :text
77
# state :integer default("active"), not null
88
# title :string not null
9-
# uid :uuid not null
9+
# uid :string
1010
# created_at :datetime not null
1111
# updated_at :datetime not null
1212
# language_id :bigint
@@ -22,14 +22,15 @@
2222
class Topic < ApplicationRecord
2323
include Searcheable
2424

25+
STATES = %i[active archived].freeze
26+
CONTENT_TYPES = %w[image/jpeg image/png image/svg+xml image/webp image/avif image/gif video/mp4].freeze
27+
2528
belongs_to :language
2629
belongs_to :provider
2730
has_many_attached :documents
2831

2932
validates :title, :language_id, :provider_id, presence: true
30-
validates :documents, content_type: %w[image/jpeg image/png image/svg+xml image/webp image/avif image/gif video/mp4], size: { less_than: 10.megabytes }
31-
32-
STATES = %i[active archived].freeze
33+
validates :documents, content_type: CONTENT_TYPES, size: { less_than: 10.megabytes }
3334

3435
enum :state, STATES.map.with_index.to_h
3536

app/views/topics/_list.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<tr>
44
<td class="text-bold-500"><%= topic.title %></td>
55
<td class="text-bold-500"><%= topic.description.present? && topic.description.truncate(25, omission: "...") %></td>
6-
<td class="text-bold-500"><%= topic.uid.truncate(10, omission: "...") %></td>
6+
<td class="text-bold-500"><%= topic.uid.truncate(10, omission: "...") if topic.uid %></td>
77
<td class="text-bold-500"><%= topic.language.name %></td>
88
<td class="text-bold-500"><%= topic.provider.name %></td>
99
<td class="text-bold-500"><%= topic.state %></td>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class ChangeTopicsUid < ActiveRecord::Migration[8.0]
2+
def up
3+
remove_column :topics, :uid
4+
add_column :topics, :uid, :string
5+
end
6+
7+
def down
8+
remove_column :topics, :uid
9+
add_column :topics, :uid, :uuid, default: -> { "gen_random_uuid()" }, null: false
10+
end
11+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/factories/topics.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# description :text
77
# state :integer default("active"), not null
88
# title :string not null
9-
# uid :uuid not null
9+
# uid :string
1010
# created_at :datetime not null
1111
# updated_at :datetime not null
1212
# language_id :bigint
@@ -23,9 +23,8 @@
2323
factory :topic do
2424
association :provider
2525
association :language
26-
title { "topic" }
27-
description { "details" }
28-
uid { SecureRandom.uuid }
26+
title { "topic title" }
27+
description { "many topic details" }
2928
state { 0 }
3029

3130
trait :archived do

spec/models/topic_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# description :text
77
# state :integer default("active"), not null
88
# title :string not null
9-
# uid :uuid not null
9+
# uid :string
1010
# created_at :datetime not null
1111
# updated_at :datetime not null
1212
# language_id :bigint

spec/requests/topics/create_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
expect(response).to redirect_to(topics_url)
1919
topic = Topic.last
20-
expect(topic.title).to eq("topic")
21-
expect(topic.description).to eq("details")
20+
expect(topic.title).to eq("topic title")
21+
expect(topic.description).to eq("many topic details")
2222
expect(topic.state).to eq("active")
2323
end
2424

0 commit comments

Comments
 (0)