Advertisement
Guest User

Untitled

a guest
May 30th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. create table if not exists audit(
  2. id serial,
  3. hi varchar
  4. );
  5.  
  6. create table if not exists trigger_tbl(
  7. id serial,
  8. log_text varchar
  9. );
  10.  
  11.  
  12.  
  13. insert into audit(hi) values ('hi');
  14. --
  15. drop trigger holiday_trigger on audit;
  16. drop function if exists checkday();
  17. create or replace function checkday()
  18. returns trigger as
  19. $$
  20. begin
  21. if (select extract(dow from current_date)) in (6,0) then
  22. raise exception 'it is holiday';
  23. end if;
  24. return new;
  25. end;
  26. $$ language plpgsql;
  27.  
  28. create TRIGGER holiday_trigger before insert or Delete or update on audit
  29. for each row execute procedure checkday();
  30.  
  31. -- table for identity
  32. CREATE SCHEMA IF NOT EXISTS dbo;
  33.  
  34. CREATE TABLE IF NOT EXISTS dbo."AspNetUsers" (
  35. "Id" VARCHAR NOT NULL,
  36. "Email" VARCHAR NULL,
  37. "EmailConfirmed" BOOLEAN NOT NULL,
  38. "PasswordHash" VARCHAR NULL,
  39. "SecurityStamp" VARCHAR NULL,
  40. "PhoneNumber" VARCHAR NULL,
  41. "PhoneNumberConfirmed" BOOLEAN NOT NULL,
  42. "TwoFactorEnabled" BOOLEAN NOT NULL,
  43. "LockoutEndDateUtc" TIMESTAMP NULL,
  44. "LockoutEnabled" BOOLEAN NOT NULL,
  45. "AccessFailedCount" INT NOT NULL,
  46. "UserName" VARCHAR NOT NULL,
  47. CONSTRAINT PK_AspNetUsers PRIMARY KEY ("Id"),
  48. CONSTRAINT UQ_AspNetUsers UNIQUE ("UserName")
  49. );
  50.  
  51. CREATE TABLE IF NOT EXISTS dbo."AspNetUserLogins" (
  52. "LoginProvider" VARCHAR NOT NULL,
  53. "ProviderKey" VARCHAR NOT NULL,
  54. "UserId" VARCHAR NOT NULL,
  55. CONSTRAINT PK_AspNetUserLogins PRIMARY KEY ("LoginProvider", "ProviderKey", "UserId"),
  56. FOREIGN KEY ("UserId") REFERENCES dbo."AspNetUsers" ("Id") ON DELETE CASCADE
  57. );
  58.  
  59. DO $$
  60. BEGIN
  61. CREATE INDEX IX_AspNetUserLogins_UserId ON dbo."AspNetUserLogins" ("UserId");
  62. EXCEPTION
  63. WHEN others THEN RAISE NOTICE 'Could not add IX_AspNetUserLogins_UserId. Does it already exist?';
  64. END
  65. $$;
  66.  
  67.  
  68. CREATE TABLE IF NOT EXISTS dbo."AspNetRoles" (
  69. "Id" VARCHAR NOT NULL,
  70. "Name" VARCHAR NOT NULL,
  71. CONSTRAINT PK_AspNetRoles PRIMARY KEY ("Id"),
  72. CONSTRAINT UQ_RoleName UNIQUE ("Name")
  73. );
  74.  
  75. CREATE TABLE IF NOT EXISTS dbo."AspNetUserClaims" (
  76. "Id" SERIAL,
  77. "UserId" VARCHAR NOT NULL,
  78. "ClaimType" VARCHAR NULL,
  79. "ClaimValue" VARCHAR NULL,
  80. CONSTRAINT PK_AspNetUserClaims PRIMARY KEY ("Id"),
  81. FOREIGN KEY ("UserId") REFERENCES dbo."AspNetUsers"("Id") ON DELETE CASCADE
  82. );
  83.  
  84. DO $$
  85. BEGIN
  86. CREATE INDEX IX_AspNetUserClaims_UserId ON dbo."AspNetUserClaims" ("UserId");
  87. EXCEPTION
  88. WHEN others THEN RAISE NOTICE 'Could not add IX_AspNetUserClaims_UserId. Does it already exist?';
  89. END
  90. $$;
  91.  
  92. CREATE TABLE IF NOT EXISTS dbo."AspNetUserRoles" (
  93. "UserId" VARCHAR NOT NULL,
  94. "RoleId" VARCHAR NOT NULL,
  95. CONSTRAINT PK_AspNetUserRoles PRIMARY KEY ("UserId", "RoleId"),
  96. FOREIGN KEY ("RoleId") REFERENCES dbo."AspNetRoles"("Id") ON DELETE CASCADE,
  97. FOREIGN KEY ("UserId") REFERENCES dbo."AspNetUsers"("Id") ON DELETE CASCADE
  98. );
  99.  
  100. DO $$
  101. BEGIN
  102. CREATE INDEX IX_AspNetUserRoles_UserId ON dbo."AspNetUserRoles"("UserId");
  103. EXCEPTION
  104. WHEN others THEN RAISE NOTICE 'Could not add IX_AspNetUserRoles_UserId. Does it already exist?';
  105. END
  106. $$;
  107.  
  108.  
  109. DO $$
  110. BEGIN
  111. CREATE INDEX IX_AspNetUserRoles_RoleId ON dbo."AspNetUserRoles"("RoleId");
  112. EXCEPTION
  113. WHEN others THEN RAISE NOTICE 'Could not add IX_AspNetUserRoles_RoleId. Does it already exist?';
  114. END
  115. $$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement