gousiosg / github-mirror

Scripts to mirror Github in a cloudy fashion
BSD 2-Clause "Simplified" License
559 stars 106 forks source link

SQLite3::SQLException: AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY #99

Closed boyang9602 closed 3 years ago

boyang9602 commented 4 years ago

Try to set up at local, this error occured: SQLite3::SQLException: AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY /home/ubuntu/.rvm/gems/ruby-2.5.7/gems/sqlite3-1.4.2/lib/sqlite3/database.rb:147:in `initialize'

I think the problem is in the 011_add_issues.rb, where the primary key is a combination of event_id and issue_id.

Below is the full output:

ubuntu@repair:~/bo$ ght-retrieve-repo tsantalis RefactoringMiner -c ght_config.yaml 
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Overriding configuration mirror_history_pages_back=5 with new value 1000
Database empty, running migrations from /home/ubuntu/.rvm/gems/ruby-2.5.7/gems/ghtorrent-0.11.1/lib/ghtorrent/migrations
Creating table users
Creating table projects
Creating table commits
Creating table commit_parents
Creating table followers
Adding organization descriminator field to table users
Updating users with default values
Creating table organization-members
Adding table commit comments
Adding table project members
Adding table watchers
Adding table pull requests
Adding table pull request history
Adding table pull request commits
Adding table pull request comments
Adding unique(name, owner) constraint to table projects
Create table project_commits
Migrating data from commits to project_commits
Adding table forks
Adding table issues
Adding issue history
SQLite3::SQLException: AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY
/home/ubuntu/.rvm/gems/ruby-2.5.7/gems/sqlite3-1.4.2/lib/sqlite3/database.rb:147:in `initialize'

below is the "adding issue history" part in 011_add_issues.rb:

    puts("Adding issue history")
    create_table :issue_events do
      Integer :event_id, :null => false
      foreign_key :issue_id, :issues, :null => false
      foreign_key :actor_id, :users, :null => false
      String :action, :null => false
      String :action_specific, :null => true, :size => 50
      DateTime :created_at, :null => false, :default=>Sequel::CURRENT_TIMESTAMP
      String :ext_ref_id, :null => false, :size => 24, :default => "0"
      primary_key [:event_id, :issue_id], :name=>:issue_events_pk
    end
stuartbates commented 3 years ago

The error is caused by passing the column names for a composite primary key as two args rather than an explicit array.

I suspect you're installing the latest version of the ghtorrent gem which currently on rubygems is v0.11.01 this version was uploaded back in September 2015.

That version has different code to what you're seeing above which was fixed in this commit.

To fix this I'd recommend installing from GitHub instead of RubyGems.

  1. Install Bundler gem (gem install bundler)
  2. Create a file in your project root called Gemfile containing this:
source 'https://rubygems.org'

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.0'

gem 'ghtorrent', github: 'gousiosg/github-mirror'
gem 'sqlite'
  1. Run bundle install to install the gems including the latest version of ghtorrent.
  2. Remove the existing database as the migrations won't run if any tables exist.
  3. Re-run your command

🎉