Skip to content

Instantly share code, notes, and snippets.

@chrisseaton
Created December 8, 2015 15:36
Show Gist options
  • Save chrisseaton/87131acdc643df050336 to your computer and use it in GitHub Desktop.
Save chrisseaton/87131acdc643df050336 to your computer and use it in GitHub Desktop.
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1
require 'active_record'
module Model
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'gems.db'
)
ActiveRecord::Schema.define do
unless ActiveRecord::Base.connection.tables.include? 'gems'
create_table :gems do |table|
table.column :name, :string
end
end
unless ActiveRecord::Base.connection.tables.include? 'versions'
create_table :versions do |table|
table.column :gem_id, :integer
table.column :version, :string
table.column :date, :date
end
end
unless ActiveRecord::Base.connection.tables.include? 'ruby_locs'
create_table :ruby_locs do |table|
table.column :version_id, :integer
table.column :loc, :integer
end
end
unless ActiveRecord::Base.connection.tables.include? 'c_locs'
create_table :c_locs do |table|
table.column :version_id, :integer
table.column :loc, :integer
end
end
end
class Gem < ActiveRecord::Base
has_many :versions
end
class Version < ActiveRecord::Base
belongs_to :gem
def name_version
"#{gem.name}-#{version}"
end
end
class RubyLOC < ActiveRecord::Base
belongs_to :version
end
class CLOC < ActiveRecord::Base
belongs_to :version
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment