Skip to content

Commit

Permalink
removing the unused created-by-user-id field (#305)
Browse files Browse the repository at this point in the history
* removing the unused created-by-user-id field

* added a new migration, and cleaned up old created-by-user references
  • Loading branch information
JaymeeH authored Dec 13, 2023
1 parent 8e4662f commit 13cc570
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 0 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
class ProjectsController < ApplicationController
def new
@project = Project.new
@project.created_by_user = current_user
end

def create
@project = Project.new
@project.metadata = form_metadata
@project.created_by_user = current_user
@project.save!
TigerdataMailer.with(project: @project).project_creation.deliver_later
redirect_to @project
Expand Down
6 changes: 4 additions & 2 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true
class Project < ApplicationRecord
belongs_to :created_by_user, class_name: "User"

def metadata
(metadata_json || {}).with_indifferent_access
end
Expand Down Expand Up @@ -45,4 +43,8 @@ def update_mediaflux(session_id:)
ProjectMediaflux.update(project: self, session_id: session_id)
Rails.logger.debug "Project #{id} has been updated in MediaFlux (asset id #{mediaflux_id}"
end

def created_by_user
User.find_by(uid: metadata[:created_by])
end
end
5 changes: 5 additions & 0 deletions db/migrate/20231213164447_remove_created_by_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveCreatedByUser < ActiveRecord::Migration[7.0]
def change
remove_column :projects, :created_by_user_id, :integer
end
end
3 changes: 1 addition & 2 deletions db/schema.rb

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

4 changes: 2 additions & 2 deletions spec/factories/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
departments: ["RDSS", "PRDS"],
directory: "big-data",
title: FFaker::Movie.title,
description: "a random description"
description: "a random description",
created_by: FactoryBot.create(:user).uid
}
end
created_by_user_id { FactoryBot.create(:user).id }
end
end

0 comments on commit 13cc570

Please sign in to comment.