dwyl / github-backup

:octocat: :back: 🆙 Backup your GitHub Issues so you can still work when (they/you are) offline.
https://github-backup.herokuapp.com
GNU General Public License v2.0
32 stars 3 forks source link

Set up Users table and get user info from github API #46

Open Cleop opened 6 years ago

Cleop commented 6 years ago

As a user of gh-backup I want to be able to identify who has written the versions of comments So that I know who to hold responsible for them

SimonLab commented 6 years ago
SimonLab commented 6 years ago

The table version already as an author column defined. I'm trying to reuse/transform this column to be a foreign_key to the new user table so that a version belongs_to a user via the column author

I've added a migration which delete and add back the author column: the column is currently a string type and can't be converted automatically to an integer that's why we need to delete it first.

    alter table(:versions) do
      remove :author
      add :author, references(:users, column: :id)
    end

The `version schema is now:

  schema "versions" do
    belongs_to :comment, Comment
    belongs_to :user, User, foreign_key: :author

    timestamps()
  end

And user:

  schema "users" do
    field :login, :string
    field :user_id, :integer
    field :avatar_url, :string
    field :html_url, :string

    has_many :comments, Comment, foreign_key: :deleted_by
    has_many :versions, Version, foreign_key: :author

    timestamps()
  end

However when creating a new version the links doesn't seem to be right has a user_id column is added and the author column doesn't seems to be linked to the user table I'm looking a bit more at the foreign_key option to see if I missed a step