-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Design DB UML. Generate models and migration. Add relationships. NB: DB contains two polymorphic tables; comments and tags.
- Loading branch information
Showing
31 changed files
with
412 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Answer < ActiveRecord::Base | ||
has_many :comments, as: :comment_on | ||
belongs_to :user | ||
belongs_to :question | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Comment < ActiveRecord::Base | ||
belongs_to :comment_on | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Question < ActiveRecord::Base | ||
has_many :comments, as: :comment_on | ||
has_many :tags, as: :subscriber | ||
has_many :answers | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Tag < ActiveRecord::Base | ||
belongs_to :subscriber | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class User < ActiveRecord::Base | ||
has_many :comments, as: :comment_on | ||
has_many :tags, as: :subscriber | ||
has_many :questions | ||
has_many :answers | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateUsers < ActiveRecord::Migration | ||
def change | ||
create_table :users do |t| | ||
t.string :uuid | ||
t.string :provider | ||
t.integer :points | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateQuestions < ActiveRecord::Migration | ||
def change | ||
create_table :questions do |t| | ||
t.integer :user_id | ||
t.string :title | ||
t.string :content | ||
t.integer :votes | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateAnswers < ActiveRecord::Migration | ||
def change | ||
create_table :answers do |t| | ||
t.integer :user_id | ||
t.integer :question_id | ||
t.string :content | ||
t.integer :votes | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateTags < ActiveRecord::Migration | ||
def change | ||
create_table :tags do |t| | ||
t.string :name | ||
t.references :subscriber, polymorphic: true, index: true | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateComments < ActiveRecord::Migration | ||
def change | ||
create_table :comments do |t| | ||
t.integer :user_id | ||
t.string :content | ||
t.integer :votes | ||
t.references :comment_on, polymorphic: true, index: true | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# encoding: UTF-8 | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 20160124145702) do | ||
|
||
create_table "answers", force: :cascade do |t| | ||
t.integer "user_id" | ||
t.integer "question_id" | ||
t.string "content" | ||
t.integer "votes" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
end | ||
|
||
create_table "comments", force: :cascade do |t| | ||
t.integer "user_id" | ||
t.string "content" | ||
t.integer "votes" | ||
t.integer "comment_on_id" | ||
t.string "comment_on_type" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
end | ||
|
||
add_index "comments", ["comment_on_type", "comment_on_id"], name: "index_comments_on_comment_on_type_and_comment_on_id" | ||
|
||
create_table "questions", force: :cascade do |t| | ||
t.integer "user_id" | ||
t.string "title" | ||
t.string "content" | ||
t.integer "votes" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
end | ||
|
||
create_table "tags", force: :cascade do |t| | ||
t.string "name" | ||
t.integer "subscriber_id" | ||
t.string "subscriber_type" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
end | ||
|
||
add_index "tags", ["subscriber_type", "subscriber_id"], name: "index_tags_on_subscriber_type_and_subscriber_id" | ||
|
||
create_table "users", force: :cascade do |t| | ||
t.string "uuid" | ||
t.string "provider" | ||
t.integer "points" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
end | ||
|
||
end |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
-- --- | ||
-- Globals | ||
-- --- | ||
|
||
-- SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; | ||
-- SET FOREIGN_KEY_CHECKS=0; | ||
|
||
-- --- | ||
-- Table 'users' | ||
-- | ||
-- --- | ||
|
||
DROP TABLE IF EXISTS `users`; | ||
|
||
CREATE TABLE `users` ( | ||
`id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, | ||
`uid` INTEGER NOT NULL DEFAULT NULL, | ||
`provider` VARCHAR NOT NULL DEFAULT 'NULL', | ||
`points` INTEGER NULL DEFAULT NULL, | ||
PRIMARY KEY (`id`) | ||
); | ||
|
||
-- --- | ||
-- Table 'questions' | ||
-- | ||
-- --- | ||
|
||
DROP TABLE IF EXISTS `questions`; | ||
|
||
CREATE TABLE `questions` ( | ||
`id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, | ||
`user_id` INTEGER NOT NULL DEFAULT NULL, | ||
`content` VARCHAR NOT NULL DEFAULT 'NULL', | ||
`votes` INTEGER NULL DEFAULT NULL, | ||
PRIMARY KEY (`id`) | ||
); | ||
|
||
-- --- | ||
-- Table 'comments' | ||
-- | ||
-- --- | ||
|
||
DROP TABLE IF EXISTS `comments`; | ||
|
||
CREATE TABLE `comments` ( | ||
`id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, | ||
`comment_on` INTEGER NOT NULL DEFAULT answer or question, | ||
`subject_id` INTEGER NOT NULL DEFAULT NULL, | ||
`user_id` INTEGER NOT NULL DEFAULT NULL, | ||
`content` VARCHAR NOT NULL DEFAULT 'NULL', | ||
`votes` INTEGER NULL DEFAULT NULL, | ||
PRIMARY KEY (`id`) | ||
); | ||
|
||
-- --- | ||
-- Table 'tags' | ||
-- | ||
-- --- | ||
|
||
DROP TABLE IF EXISTS `tags`; | ||
|
||
CREATE TABLE `tags` ( | ||
`id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, | ||
`name` VARCHAR NOT NULL DEFAULT 'NULL', | ||
`subscribed_users` VARCHAR NOT NULL DEFAULT 'NULL' COMMENT 'This will be like a list of the ids of users that have this ', | ||
`subscribed_questions` VARCHAR NULL DEFAULT NULL, | ||
PRIMARY KEY (`id`) | ||
); | ||
|
||
-- --- | ||
-- Table 'answers' | ||
-- | ||
-- --- | ||
|
||
DROP TABLE IF EXISTS `answers`; | ||
|
||
CREATE TABLE `answers` ( | ||
`id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, | ||
`question_id` INTEGER NOT NULL DEFAULT NULL, | ||
`content` VARCHAR NOT NULL DEFAULT 'NULL', | ||
`votes` INTEGER NULL DEFAULT NULL, | ||
`user_id` INTEGER NOT NULL DEFAULT NULL, | ||
PRIMARY KEY (`id`) | ||
); | ||
|
||
-- --- | ||
-- Foreign Keys | ||
-- --- | ||
|
||
ALTER TABLE `questions` ADD FOREIGN KEY (user_id) REFERENCES `users` (`id`); | ||
ALTER TABLE `comments` ADD FOREIGN KEY (user_id) REFERENCES `users` (`id`); | ||
ALTER TABLE `answers` ADD FOREIGN KEY (question_id) REFERENCES `questions` (`id`); | ||
ALTER TABLE `answers` ADD FOREIGN KEY (user_id) REFERENCES `users` (`id`); | ||
|
||
-- --- | ||
-- Table Properties | ||
-- --- | ||
|
||
-- ALTER TABLE `users` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; | ||
-- ALTER TABLE `questions` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; | ||
-- ALTER TABLE `comments` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; | ||
-- ALTER TABLE `tags` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; | ||
-- ALTER TABLE `answers` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; | ||
|
||
-- --- | ||
-- Test Data | ||
-- --- | ||
|
||
-- INSERT INTO `users` (`id`,`uid`,`provider`,`points`) VALUES | ||
-- ('','','',''); | ||
-- INSERT INTO `questions` (`id`,`user_id`,`content`,`votes`) VALUES | ||
-- ('','','',''); | ||
-- INSERT INTO `comments` (`id`,`comment_on`,`subject_id`,`user_id`,`content`,`votes`) VALUES | ||
-- ('','','','','',''); | ||
-- INSERT INTO `tags` (`id`,`name`,`subscribed_users`,`subscribed_questions`) VALUES | ||
-- ('','','',''); | ||
-- INSERT INTO `answers` (`id`,`question_id`,`content`,`votes`,`user_id`) VALUES | ||
-- ('','','','',''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Answer, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Comment, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Question, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Tag, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe User, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
Oops, something went wrong.