sqlite.sql 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * This is the database schema for testing Sqlite support of Gii module.
  3. * The database setup in config.php is required to perform then relevant tests:
  4. */
  5. DROP TABLE IF EXISTS "product_language";
  6. DROP TABLE IF EXISTS "product";
  7. DROP TABLE IF EXISTS "supplier";
  8. DROP TABLE IF EXISTS "category_photo";
  9. DROP TABLE IF EXISTS "category";
  10. DROP TABLE IF EXISTS "customer";
  11. DROP TABLE IF EXISTS "profile";
  12. CREATE TABLE "profile" (
  13. id INTEGER NOT NULL,
  14. description varchar(128) NOT NULL,
  15. PRIMARY KEY (id)
  16. );
  17. CREATE TABLE "customer" (
  18. id INTEGER NOT NULL,
  19. email varchar(128) NOT NULL,
  20. name varchar(128),
  21. address text,
  22. status INTEGER DEFAULT 0,
  23. profile_id INTEGER,
  24. PRIMARY KEY (id)
  25. );
  26. CREATE TABLE "category" (
  27. id INTEGER NOT NULL,
  28. language_code varchar(3) NOT NULL,
  29. name varchar(128) NOT NULL,
  30. PRIMARY KEY (id),
  31. UNIQUE (id, language_code)
  32. );
  33. CREATE TABLE "category_photo" (
  34. id INTEGER NOT NULL,
  35. category_id INTEGER NOT NULL REFERENCES "category" (id) ON DELETE CASCADE,
  36. display_number INTEGER NOT NULL DEFAULT 0,
  37. PRIMARY KEY (id),
  38. UNIQUE (category_id, display_number)
  39. );
  40. CREATE TABLE "supplier" (
  41. id INTEGER NOT NULL,
  42. name varchar(128) NOT NULL,
  43. PRIMARY KEY (id)
  44. );
  45. CREATE TABLE "attribute" (
  46. id INTEGER NOT NULL,
  47. supplier_id INTEGER NOT NULL REFERENCES "supplier" (id) ON DELETE CASCADE,
  48. name varchar(128) NOT NULL,
  49. value varchar(128) NOT NULL,
  50. PRIMARY KEY (id)
  51. );
  52. CREATE TABLE "product" (
  53. id INTEGER NOT NULL,
  54. supplier_id INTEGER NOT NULL REFERENCES "supplier" (id) ON DELETE CASCADE,
  55. category_language_code varchar(3) NOT NULL,
  56. category_id INTEGER NOT NULL,
  57. internal_name varchar(128),
  58. PRIMARY KEY (id, supplier_id),
  59. UNIQUE (category_id, category_language_code),
  60. CONSTRAINT product_category_id_category_language_code_fkey FOREIGN KEY (category_id, category_language_code) REFERENCES "category" (id, language_code) ON DELETE CASCADE
  61. );
  62. CREATE TABLE "product_language" (
  63. id INTEGER NOT NULL,
  64. supplier_id INTEGER NOT NULL REFERENCES "supplier" (id) ON DELETE CASCADE,
  65. language_code varchar(3),
  66. name varchar(128),
  67. PRIMARY KEY (id, supplier_id),
  68. UNIQUE (id, supplier_id, language_code),
  69. UNIQUE (supplier_id),
  70. CONSTRAINT product_language_id_supplier_id_fkey FOREIGN KEY (supplier_id, id) REFERENCES "product" (supplier_id, id) ON DELETE CASCADE
  71. );
  72. INSERT INTO "profile" (description) VALUES ('profile customer 1');
  73. INSERT INTO "profile" (description) VALUES ('profile customer 3');
  74. INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
  75. INSERT INTO "customer" (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
  76. INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);