Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • C cjk_web
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • kamekame
  • cjk_web
  • Merge requests
  • !1

Fix/unique secndary indices

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged iomz requested to merge fix/unique-secndary-indices into master Oct 23, 2017
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 2

SQLite3のUNIQUE constraintで複数のcolumn(:emailと:login_secretとか)を指定するとINNER JOIN(ON)されてしまうので、Migrationファイルを記述する際には分けるとDBにも反映されます。 ということで出来ました。

23:17 iomz@malvaceae:~/auto-id/cjk/cjk_web % rm db/development.sqlite3
23:17 iomz@malvaceae:~/auto-id/cjk/cjk_web % bundle exec rake db:migrate
== 20171002035550 CreateAttendees: migrating ==================================
-- create_table(:attendees)
   -> 0.0014s
-- add_index(:attendees, :email, {:unique=>true})
   -> 0.0009s
-- add_index(:attendees, :login_secret, {:unique=>true})
   -> 0.0008s
== 20171002035550 CreateAttendees: migrated (0.0034s) =========================

== 20171002035604 CreateSessions: migrating ===================================
-- create_table(:sessions)
   -> 0.0012s
== 20171002035604 CreateSessions: migrated (0.0013s) ==========================

== 20171002035622 CreateOrganizations: migrating ==============================
-- create_table(:organizations)
   -> 0.0010s
== 20171002035622 CreateOrganizations: migrated (0.0011s) =====================

== 20171002035636 CreatePresentations: migrating ==============================
-- create_table(:presentations)
   -> 0.0023s
== 20171002035636 CreatePresentations: migrated (0.0024s) =====================

== 20171002042232 CreateRooms: migrating ======================================
-- create_table(:rooms)
   -> 0.0011s
== 20171002042232 CreateRooms: migrated (0.0012s) =============================

== 20171008133031 CreatePhotos: migrating =====================================
-- create_table(:photos)
   -> 0.0012s
== 20171008133031 CreatePhotos: migrated (0.0014s) ============================

== 20171018125033 CreatePresentationVotes: migrating ==========================
-- create_table(:presentation_votes)
   -> 0.0012s
== 20171018125033 CreatePresentationVotes: migrated (0.0012s) =================

== 20171018125057 CreateQuestionerVotes: migrating ============================
-- create_table(:questioner_votes)
   -> 0.0011s
== 20171018125057 CreateQuestionerVotes: migrated (0.0012s) ===================

23:17 iomz@malvaceae:~/auto-id/cjk/cjk_web % sqlite3 db/development.sqlite3
SQLite version 3.16.0 2016-11-04 19:09:39
Enter ".help" for usage hints.
sqlite> .schema
CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY);
CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
CREATE TABLE "attendees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar NOT NULL, "name" varchar NOT NULL, "password_digest" varchar NOT NULL, "organization_id" integer NOT NULL, "login_secret" varchar NOT NULL);
CREATE UNIQUE INDEX "index_attendees_on_email" ON "attendees" ("email");
CREATE UNIQUE INDEX "index_attendees_on_login_secret" ON "attendees" ("login_secret");
CREATE TABLE "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar NOT NULL, "chairperson_id" integer NOT NULL, "room_id" integer NOT NULL);
CREATE TABLE "organizations" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL);
CREATE TABLE "presentations" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "presenter_id" integer NOT NULL, "title" varchar NOT NULL, "slide_title" varchar DEFAULT 'Not Uploaded', "slide" boolean DEFAULT 'f' NOT NULL, "session_id" integer NOT NULL, "start_time" datetime NOT NULL, "finish_time" datetime NOT NULL);
CREATE TABLE "rooms" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL);
CREATE TABLE "photos" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "file_name" varchar NOT NULL);
CREATE TABLE "presentation_votes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "voter_id" varchar NOT NULL, "presentation_id" varchar NOT NULL);
CREATE TABLE "questioner_votes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "voter_id" varchar NOT NULL, "questioner_id" varchar NOT NULL);
sqlite> insert into attendees values(0,'iomz@hoge.co.jp','iomz','hash',0,'foo');
sqlite> insert into attendees values(1,'iomz@hoge.com','iomz','hash',0,'foo');
Error: UNIQUE constraint failed: attendees.login_secret
sqlite> insert into attendees values(1,'iomz@hoge.co.jp','iomz','hash',0,'bar');
Error: UNIQUE constraint failed: attendees.email
sqlite> .quit
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: fix/unique-secndary-indices