aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-12-26 21:42:31 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-12-26 21:42:31 +0900
commit24c3623eaa1b82bcf97cb4d5a4f131d9cc2a856f (patch)
tree2959676f88738efdba614887863bf264be9f2eba
parenta7fa8aa9ab401dd11682013005c1c8b7b3a97922 (diff)
downloadpoe-24c3623eaa1b82bcf97cb4d5a4f131d9cc2a856f.tar.gz
create models
-rw-r--r--.gitignore3
-rw-r--r--app/models/compiler.rb2
-rw-r--r--app/models/result.rb4
-rw-r--r--app/models/snippet.rb3
-rw-r--r--config/database.yml2
-rw-r--r--db/migrate/20151226110833_create_snippets.rb10
-rw-r--r--db/migrate/20151226120525_create_compilers.rb12
-rw-r--r--db/migrate/20151226120716_create_results.rb13
-rw-r--r--db/schema.rb42
-rw-r--r--db/seeds.rb5
10 files changed, 95 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 48fb168..9df4381 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,6 @@
# Ignore Byebug command history file.
.byebug_history
+
+# Vim
+.*.sw*
diff --git a/app/models/compiler.rb b/app/models/compiler.rb
new file mode 100644
index 0000000..0ec28cc
--- /dev/null
+++ b/app/models/compiler.rb
@@ -0,0 +1,2 @@
+class Compiler < ApplicationRecord
+end
diff --git a/app/models/result.rb b/app/models/result.rb
new file mode 100644
index 0000000..8ca10e2
--- /dev/null
+++ b/app/models/result.rb
@@ -0,0 +1,4 @@
+class Result < ApplicationRecord
+ belongs_to :snippet
+ belongs_to :compiler
+end
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
new file mode 100644
index 0000000..9870f4e
--- /dev/null
+++ b/app/models/snippet.rb
@@ -0,0 +1,3 @@
+class Snippet < ApplicationRecord
+ has_many :result
+end
diff --git a/config/database.yml b/config/database.yml
index b8b0f2c..749ab31 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -11,7 +11,7 @@
#
default: &default
adapter: mysql2
- encoding: utf8
+ encoding: utf8mb4
pool: 5
username: root
password:
diff --git a/db/migrate/20151226110833_create_snippets.rb b/db/migrate/20151226110833_create_snippets.rb
new file mode 100644
index 0000000..6feb625
--- /dev/null
+++ b/db/migrate/20151226110833_create_snippets.rb
@@ -0,0 +1,10 @@
+class CreateSnippets < ActiveRecord::Migration[5.0]
+ def change
+ create_table :snippets do |t|
+ t.string :title, null: true
+ t.binary :code, null: false
+
+ t.datetime :created_at, null: false
+ end
+ end
+end
diff --git a/db/migrate/20151226120525_create_compilers.rb b/db/migrate/20151226120525_create_compilers.rb
new file mode 100644
index 0000000..5929b0f
--- /dev/null
+++ b/db/migrate/20151226120525_create_compilers.rb
@@ -0,0 +1,12 @@
+class CreateCompilers < ActiveRecord::Migration[5.0]
+ def change
+ create_table :compilers do |t|
+ t.string :language, null: false, limit: 64
+ t.string :version, null: false, limit: 64
+
+ t.timestamps null: false
+ end
+
+ add_index :compilers, [:language, :version], unique: true
+ end
+end
diff --git a/db/migrate/20151226120716_create_results.rb b/db/migrate/20151226120716_create_results.rb
new file mode 100644
index 0000000..612a03e
--- /dev/null
+++ b/db/migrate/20151226120716_create_results.rb
@@ -0,0 +1,13 @@
+class CreateResults < ActiveRecord::Migration[5.0]
+ def change
+ create_table :results do |t|
+ t.belongs_to :snippet, index: true, foreign_key: true, null: false
+ t.belongs_to :compiler, index: true, foreign_key: true, null: false
+ t.binary :output, null: false
+
+ t.datetime :created_at, null: false
+ end
+
+ add_index :results, [:snippet_id, :compiler_id], unique: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000..5812893
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,42 @@
+# 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: 20151226120716) do
+
+ create_table "compilers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" do |t|
+ t.string "language", limit: 64, null: false
+ t.string "version", limit: 64, null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["language", "version"], name: "index_compilers_on_language_and_version", unique: true, using: :btree
+ end
+
+ create_table "results", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" do |t|
+ t.integer "snippet_id", null: false
+ t.integer "compiler_id", null: false
+ t.binary "output", limit: 65535, null: false
+ t.datetime "created_at", null: false
+ t.index ["compiler_id"], name: "index_results_on_compiler_id", using: :btree
+ t.index ["snippet_id", "compiler_id"], name: "index_results_on_snippet_id_and_compiler_id", unique: true, using: :btree
+ t.index ["snippet_id"], name: "index_results_on_snippet_id", using: :btree
+ end
+
+ create_table "snippets", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" do |t|
+ t.string "title"
+ t.binary "code", limit: 65535, null: false
+ t.datetime "created_at", null: false
+ end
+
+ add_foreign_key "results", "compilers"
+ add_foreign_key "results", "snippets"
+end
diff --git a/db/seeds.rb b/db/seeds.rb
index cfadd24..f16f4fa 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -5,3 +5,8 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
+
+if Rails.env.development?
+ # just eval
+ Compiler.create(language: "ruby", version: "!!unsafe!!")
+end