Openstatus www.openstatus.dev

๐Ÿ—ƒ๏ธ database update (#592)

* ๐Ÿ—ƒ๏ธ database update

* ๐Ÿ—ƒ๏ธ database update

* ๐Ÿ—ƒ๏ธ database update

authored by

Thibault Le Ouay and committed by
GitHub
ad563157 4ebf94fc

+1386 -31
+8 -5
apps/server/src/checker/index.ts
··· 115 115 ) 116 116 .get(); 117 117 if (incident === undefined) { 118 - await db.insert(incidentTable).values({ 119 - monitorId: Number(monitorId), 120 - workspaceId: monitor.workspaceId, 121 - startedAt: new Date(cronTimestamp), 122 - }); 118 + await db 119 + .insert(incidentTable) 120 + .values({ 121 + monitorId: Number(monitorId), 122 + workspaceId: monitor.workspaceId, 123 + startedAt: new Date(cronTimestamp), 124 + }) 125 + .onConflictDoNothing(); 123 126 124 127 await triggerAlerting({ monitorId, statusCode, message, region }); 125 128 }
+27
packages/db/drizzle/0016_certain_praxagora.sql
··· 1 + CREATE TABLE `incident_new` ( 2 + `id` integer PRIMARY KEY NOT NULL, 3 + `title` text DEFAULT '' NOT NULL, 4 + `summary` text DEFAULT '' NOT NULL, 5 + `status` text DEFAULT 'triage' NOT NULL, 6 + `monitor_id` integer, 7 + `workspace_id` integer, 8 + `started_at` integer DEFAULT (strftime('%s', 'now')) NOT NULL, 9 + `acknowledged_at` integer, 10 + `acknowledged_by` integer, 11 + `resolved_at` integer, 12 + `resolved_by` integer, 13 + `created_at` integer DEFAULT (strftime('%s', 'now')), 14 + `updated_at` integer DEFAULT (strftime('%s', 'now')), 15 + FOREIGN KEY (`monitor_id`) REFERENCES `monitor`(`id`) ON UPDATE no action ON DELETE set default, 16 + FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE no action ON DELETE no action, 17 + FOREIGN KEY (`acknowledged_by`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action, 18 + FOREIGN KEY (`resolved_by`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action 19 + ); 20 + --> statement-breakpoint 21 + CREATE UNIQUE INDEX `composite_incident_new_id_started_at_unique` ON `incident_new` (`id`,`started_at`); 22 + --> statement-breakpoint 23 + INSERT INTO incident_new(`id`,`title`,`summary`,`status`,`monitor_id`,`workspace_id`,`started_at`,`acknowledged_at`,`acknowledged_by`,`resolved_at`,`resolved_by`,`created_at`,`updated_at`) SELECT * FROM incident; 24 + --> statement-breakpoint 25 + DROP TABLE incident; 26 + --> statement-breakpoint 27 + ALTER TABLE incident_new RENAME TO incident;
+1298
packages/db/drizzle/meta/0016_snapshot.json
··· 1 + { 2 + "version": "5", 3 + "dialect": "sqlite", 4 + "id": "d3626cd5-956f-4a64-9c70-02e5ee44cde0", 5 + "prevId": "f5a77857-319d-4575-b570-f0aacb9eab35", 6 + "tables": { 7 + "status_report_to_monitors": { 8 + "name": "status_report_to_monitors", 9 + "columns": { 10 + "monitor_id": { 11 + "name": "monitor_id", 12 + "type": "integer", 13 + "primaryKey": false, 14 + "notNull": true, 15 + "autoincrement": false 16 + }, 17 + "status_report_id": { 18 + "name": "status_report_id", 19 + "type": "integer", 20 + "primaryKey": false, 21 + "notNull": true, 22 + "autoincrement": false 23 + } 24 + }, 25 + "indexes": {}, 26 + "foreignKeys": { 27 + "status_report_to_monitors_monitor_id_monitor_id_fk": { 28 + "name": "status_report_to_monitors_monitor_id_monitor_id_fk", 29 + "tableFrom": "status_report_to_monitors", 30 + "tableTo": "monitor", 31 + "columnsFrom": ["monitor_id"], 32 + "columnsTo": ["id"], 33 + "onDelete": "cascade", 34 + "onUpdate": "no action" 35 + }, 36 + "status_report_to_monitors_status_report_id_status_report_id_fk": { 37 + "name": "status_report_to_monitors_status_report_id_status_report_id_fk", 38 + "tableFrom": "status_report_to_monitors", 39 + "tableTo": "status_report", 40 + "columnsFrom": ["status_report_id"], 41 + "columnsTo": ["id"], 42 + "onDelete": "cascade", 43 + "onUpdate": "no action" 44 + } 45 + }, 46 + "compositePrimaryKeys": { 47 + "status_report_to_monitors_monitor_id_status_report_id_pk": { 48 + "columns": ["monitor_id", "status_report_id"] 49 + } 50 + }, 51 + "uniqueConstraints": {} 52 + }, 53 + "status_reports_to_pages": { 54 + "name": "status_reports_to_pages", 55 + "columns": { 56 + "page_id": { 57 + "name": "page_id", 58 + "type": "integer", 59 + "primaryKey": false, 60 + "notNull": true, 61 + "autoincrement": false 62 + }, 63 + "status_report_id": { 64 + "name": "status_report_id", 65 + "type": "integer", 66 + "primaryKey": false, 67 + "notNull": true, 68 + "autoincrement": false 69 + } 70 + }, 71 + "indexes": {}, 72 + "foreignKeys": { 73 + "status_reports_to_pages_page_id_page_id_fk": { 74 + "name": "status_reports_to_pages_page_id_page_id_fk", 75 + "tableFrom": "status_reports_to_pages", 76 + "tableTo": "page", 77 + "columnsFrom": ["page_id"], 78 + "columnsTo": ["id"], 79 + "onDelete": "cascade", 80 + "onUpdate": "no action" 81 + }, 82 + "status_reports_to_pages_status_report_id_status_report_id_fk": { 83 + "name": "status_reports_to_pages_status_report_id_status_report_id_fk", 84 + "tableFrom": "status_reports_to_pages", 85 + "tableTo": "status_report", 86 + "columnsFrom": ["status_report_id"], 87 + "columnsTo": ["id"], 88 + "onDelete": "cascade", 89 + "onUpdate": "no action" 90 + } 91 + }, 92 + "compositePrimaryKeys": { 93 + "status_reports_to_pages_page_id_status_report_id_pk": { 94 + "columns": ["page_id", "status_report_id"] 95 + } 96 + }, 97 + "uniqueConstraints": {} 98 + }, 99 + "status_report": { 100 + "name": "status_report", 101 + "columns": { 102 + "id": { 103 + "name": "id", 104 + "type": "integer", 105 + "primaryKey": true, 106 + "notNull": true, 107 + "autoincrement": false 108 + }, 109 + "status": { 110 + "name": "status", 111 + "type": "text", 112 + "primaryKey": false, 113 + "notNull": true, 114 + "autoincrement": false 115 + }, 116 + "title": { 117 + "name": "title", 118 + "type": "text(256)", 119 + "primaryKey": false, 120 + "notNull": true, 121 + "autoincrement": false 122 + }, 123 + "workspace_id": { 124 + "name": "workspace_id", 125 + "type": "integer", 126 + "primaryKey": false, 127 + "notNull": false, 128 + "autoincrement": false 129 + }, 130 + "created_at": { 131 + "name": "created_at", 132 + "type": "integer", 133 + "primaryKey": false, 134 + "notNull": false, 135 + "autoincrement": false, 136 + "default": "(strftime('%s', 'now'))" 137 + }, 138 + "updated_at": { 139 + "name": "updated_at", 140 + "type": "integer", 141 + "primaryKey": false, 142 + "notNull": false, 143 + "autoincrement": false, 144 + "default": "(strftime('%s', 'now'))" 145 + } 146 + }, 147 + "indexes": {}, 148 + "foreignKeys": { 149 + "status_report_workspace_id_workspace_id_fk": { 150 + "name": "status_report_workspace_id_workspace_id_fk", 151 + "tableFrom": "status_report", 152 + "tableTo": "workspace", 153 + "columnsFrom": ["workspace_id"], 154 + "columnsTo": ["id"], 155 + "onDelete": "no action", 156 + "onUpdate": "no action" 157 + } 158 + }, 159 + "compositePrimaryKeys": {}, 160 + "uniqueConstraints": {} 161 + }, 162 + "status_report_update": { 163 + "name": "status_report_update", 164 + "columns": { 165 + "id": { 166 + "name": "id", 167 + "type": "integer", 168 + "primaryKey": true, 169 + "notNull": true, 170 + "autoincrement": false 171 + }, 172 + "status": { 173 + "name": "status", 174 + "type": "text(4)", 175 + "primaryKey": false, 176 + "notNull": true, 177 + "autoincrement": false 178 + }, 179 + "date": { 180 + "name": "date", 181 + "type": "integer", 182 + "primaryKey": false, 183 + "notNull": true, 184 + "autoincrement": false 185 + }, 186 + "message": { 187 + "name": "message", 188 + "type": "text", 189 + "primaryKey": false, 190 + "notNull": true, 191 + "autoincrement": false 192 + }, 193 + "status_report_id": { 194 + "name": "status_report_id", 195 + "type": "integer", 196 + "primaryKey": false, 197 + "notNull": true, 198 + "autoincrement": false 199 + }, 200 + "created_at": { 201 + "name": "created_at", 202 + "type": "integer", 203 + "primaryKey": false, 204 + "notNull": false, 205 + "autoincrement": false, 206 + "default": "(strftime('%s', 'now'))" 207 + }, 208 + "updated_at": { 209 + "name": "updated_at", 210 + "type": "integer", 211 + "primaryKey": false, 212 + "notNull": false, 213 + "autoincrement": false, 214 + "default": "(strftime('%s', 'now'))" 215 + } 216 + }, 217 + "indexes": {}, 218 + "foreignKeys": { 219 + "status_report_update_status_report_id_status_report_id_fk": { 220 + "name": "status_report_update_status_report_id_status_report_id_fk", 221 + "tableFrom": "status_report_update", 222 + "tableTo": "status_report", 223 + "columnsFrom": ["status_report_id"], 224 + "columnsTo": ["id"], 225 + "onDelete": "cascade", 226 + "onUpdate": "no action" 227 + } 228 + }, 229 + "compositePrimaryKeys": {}, 230 + "uniqueConstraints": {} 231 + }, 232 + "integration": { 233 + "name": "integration", 234 + "columns": { 235 + "id": { 236 + "name": "id", 237 + "type": "integer", 238 + "primaryKey": true, 239 + "notNull": true, 240 + "autoincrement": false 241 + }, 242 + "name": { 243 + "name": "name", 244 + "type": "text(256)", 245 + "primaryKey": false, 246 + "notNull": true, 247 + "autoincrement": false 248 + }, 249 + "workspace_id": { 250 + "name": "workspace_id", 251 + "type": "integer", 252 + "primaryKey": false, 253 + "notNull": false, 254 + "autoincrement": false 255 + }, 256 + "credential": { 257 + "name": "credential", 258 + "type": "text", 259 + "primaryKey": false, 260 + "notNull": false, 261 + "autoincrement": false 262 + }, 263 + "external_id": { 264 + "name": "external_id", 265 + "type": "text", 266 + "primaryKey": false, 267 + "notNull": true, 268 + "autoincrement": false 269 + }, 270 + "created_at": { 271 + "name": "created_at", 272 + "type": "integer", 273 + "primaryKey": false, 274 + "notNull": false, 275 + "autoincrement": false, 276 + "default": "(strftime('%s', 'now'))" 277 + }, 278 + "updated_at": { 279 + "name": "updated_at", 280 + "type": "integer", 281 + "primaryKey": false, 282 + "notNull": false, 283 + "autoincrement": false, 284 + "default": "(strftime('%s', 'now'))" 285 + }, 286 + "data": { 287 + "name": "data", 288 + "type": "text", 289 + "primaryKey": false, 290 + "notNull": true, 291 + "autoincrement": false 292 + } 293 + }, 294 + "indexes": {}, 295 + "foreignKeys": { 296 + "integration_workspace_id_workspace_id_fk": { 297 + "name": "integration_workspace_id_workspace_id_fk", 298 + "tableFrom": "integration", 299 + "tableTo": "workspace", 300 + "columnsFrom": ["workspace_id"], 301 + "columnsTo": ["id"], 302 + "onDelete": "no action", 303 + "onUpdate": "no action" 304 + } 305 + }, 306 + "compositePrimaryKeys": {}, 307 + "uniqueConstraints": {} 308 + }, 309 + "page": { 310 + "name": "page", 311 + "columns": { 312 + "id": { 313 + "name": "id", 314 + "type": "integer", 315 + "primaryKey": true, 316 + "notNull": true, 317 + "autoincrement": false 318 + }, 319 + "workspace_id": { 320 + "name": "workspace_id", 321 + "type": "integer", 322 + "primaryKey": false, 323 + "notNull": true, 324 + "autoincrement": false 325 + }, 326 + "title": { 327 + "name": "title", 328 + "type": "text", 329 + "primaryKey": false, 330 + "notNull": true, 331 + "autoincrement": false 332 + }, 333 + "description": { 334 + "name": "description", 335 + "type": "text", 336 + "primaryKey": false, 337 + "notNull": true, 338 + "autoincrement": false 339 + }, 340 + "icon": { 341 + "name": "icon", 342 + "type": "text(256)", 343 + "primaryKey": false, 344 + "notNull": false, 345 + "autoincrement": false, 346 + "default": "''" 347 + }, 348 + "slug": { 349 + "name": "slug", 350 + "type": "text(256)", 351 + "primaryKey": false, 352 + "notNull": true, 353 + "autoincrement": false 354 + }, 355 + "custom_domain": { 356 + "name": "custom_domain", 357 + "type": "text(256)", 358 + "primaryKey": false, 359 + "notNull": true, 360 + "autoincrement": false 361 + }, 362 + "published": { 363 + "name": "published", 364 + "type": "integer", 365 + "primaryKey": false, 366 + "notNull": false, 367 + "autoincrement": false, 368 + "default": false 369 + }, 370 + "created_at": { 371 + "name": "created_at", 372 + "type": "integer", 373 + "primaryKey": false, 374 + "notNull": false, 375 + "autoincrement": false, 376 + "default": "(strftime('%s', 'now'))" 377 + }, 378 + "updated_at": { 379 + "name": "updated_at", 380 + "type": "integer", 381 + "primaryKey": false, 382 + "notNull": false, 383 + "autoincrement": false, 384 + "default": "(strftime('%s', 'now'))" 385 + } 386 + }, 387 + "indexes": { 388 + "page_slug_unique": { 389 + "name": "page_slug_unique", 390 + "columns": ["slug"], 391 + "isUnique": true 392 + } 393 + }, 394 + "foreignKeys": { 395 + "page_workspace_id_workspace_id_fk": { 396 + "name": "page_workspace_id_workspace_id_fk", 397 + "tableFrom": "page", 398 + "tableTo": "workspace", 399 + "columnsFrom": ["workspace_id"], 400 + "columnsTo": ["id"], 401 + "onDelete": "cascade", 402 + "onUpdate": "no action" 403 + } 404 + }, 405 + "compositePrimaryKeys": {}, 406 + "uniqueConstraints": {} 407 + }, 408 + "monitor": { 409 + "name": "monitor", 410 + "columns": { 411 + "id": { 412 + "name": "id", 413 + "type": "integer", 414 + "primaryKey": true, 415 + "notNull": true, 416 + "autoincrement": false 417 + }, 418 + "job_type": { 419 + "name": "job_type", 420 + "type": "text", 421 + "primaryKey": false, 422 + "notNull": true, 423 + "autoincrement": false, 424 + "default": "'other'" 425 + }, 426 + "periodicity": { 427 + "name": "periodicity", 428 + "type": "text", 429 + "primaryKey": false, 430 + "notNull": true, 431 + "autoincrement": false, 432 + "default": "'other'" 433 + }, 434 + "status": { 435 + "name": "status", 436 + "type": "text", 437 + "primaryKey": false, 438 + "notNull": true, 439 + "autoincrement": false, 440 + "default": "'active'" 441 + }, 442 + "active": { 443 + "name": "active", 444 + "type": "integer", 445 + "primaryKey": false, 446 + "notNull": false, 447 + "autoincrement": false, 448 + "default": false 449 + }, 450 + "regions": { 451 + "name": "regions", 452 + "type": "text", 453 + "primaryKey": false, 454 + "notNull": true, 455 + "autoincrement": false, 456 + "default": "''" 457 + }, 458 + "url": { 459 + "name": "url", 460 + "type": "text(2048)", 461 + "primaryKey": false, 462 + "notNull": true, 463 + "autoincrement": false 464 + }, 465 + "name": { 466 + "name": "name", 467 + "type": "text(256)", 468 + "primaryKey": false, 469 + "notNull": true, 470 + "autoincrement": false, 471 + "default": "''" 472 + }, 473 + "description": { 474 + "name": "description", 475 + "type": "text", 476 + "primaryKey": false, 477 + "notNull": true, 478 + "autoincrement": false, 479 + "default": "''" 480 + }, 481 + "headers": { 482 + "name": "headers", 483 + "type": "text", 484 + "primaryKey": false, 485 + "notNull": false, 486 + "autoincrement": false, 487 + "default": "''" 488 + }, 489 + "body": { 490 + "name": "body", 491 + "type": "text", 492 + "primaryKey": false, 493 + "notNull": false, 494 + "autoincrement": false, 495 + "default": "''" 496 + }, 497 + "method": { 498 + "name": "method", 499 + "type": "text", 500 + "primaryKey": false, 501 + "notNull": false, 502 + "autoincrement": false, 503 + "default": "'GET'" 504 + }, 505 + "workspace_id": { 506 + "name": "workspace_id", 507 + "type": "integer", 508 + "primaryKey": false, 509 + "notNull": false, 510 + "autoincrement": false 511 + }, 512 + "created_at": { 513 + "name": "created_at", 514 + "type": "integer", 515 + "primaryKey": false, 516 + "notNull": false, 517 + "autoincrement": false, 518 + "default": "(strftime('%s', 'now'))" 519 + }, 520 + "updated_at": { 521 + "name": "updated_at", 522 + "type": "integer", 523 + "primaryKey": false, 524 + "notNull": false, 525 + "autoincrement": false, 526 + "default": "(strftime('%s', 'now'))" 527 + } 528 + }, 529 + "indexes": {}, 530 + "foreignKeys": { 531 + "monitor_workspace_id_workspace_id_fk": { 532 + "name": "monitor_workspace_id_workspace_id_fk", 533 + "tableFrom": "monitor", 534 + "tableTo": "workspace", 535 + "columnsFrom": ["workspace_id"], 536 + "columnsTo": ["id"], 537 + "onDelete": "no action", 538 + "onUpdate": "no action" 539 + } 540 + }, 541 + "compositePrimaryKeys": {}, 542 + "uniqueConstraints": {} 543 + }, 544 + "monitors_to_pages": { 545 + "name": "monitors_to_pages", 546 + "columns": { 547 + "monitor_id": { 548 + "name": "monitor_id", 549 + "type": "integer", 550 + "primaryKey": false, 551 + "notNull": true, 552 + "autoincrement": false 553 + }, 554 + "page_id": { 555 + "name": "page_id", 556 + "type": "integer", 557 + "primaryKey": false, 558 + "notNull": true, 559 + "autoincrement": false 560 + } 561 + }, 562 + "indexes": {}, 563 + "foreignKeys": { 564 + "monitors_to_pages_monitor_id_monitor_id_fk": { 565 + "name": "monitors_to_pages_monitor_id_monitor_id_fk", 566 + "tableFrom": "monitors_to_pages", 567 + "tableTo": "monitor", 568 + "columnsFrom": ["monitor_id"], 569 + "columnsTo": ["id"], 570 + "onDelete": "cascade", 571 + "onUpdate": "no action" 572 + }, 573 + "monitors_to_pages_page_id_page_id_fk": { 574 + "name": "monitors_to_pages_page_id_page_id_fk", 575 + "tableFrom": "monitors_to_pages", 576 + "tableTo": "page", 577 + "columnsFrom": ["page_id"], 578 + "columnsTo": ["id"], 579 + "onDelete": "cascade", 580 + "onUpdate": "no action" 581 + } 582 + }, 583 + "compositePrimaryKeys": { 584 + "monitors_to_pages_monitor_id_page_id_pk": { 585 + "columns": ["monitor_id", "page_id"] 586 + } 587 + }, 588 + "uniqueConstraints": {} 589 + }, 590 + "user": { 591 + "name": "user", 592 + "columns": { 593 + "id": { 594 + "name": "id", 595 + "type": "integer", 596 + "primaryKey": true, 597 + "notNull": true, 598 + "autoincrement": false 599 + }, 600 + "tenant_id": { 601 + "name": "tenant_id", 602 + "type": "text(256)", 603 + "primaryKey": false, 604 + "notNull": false, 605 + "autoincrement": false 606 + }, 607 + "first_name": { 608 + "name": "first_name", 609 + "type": "text", 610 + "primaryKey": false, 611 + "notNull": false, 612 + "autoincrement": false, 613 + "default": "''" 614 + }, 615 + "last_name": { 616 + "name": "last_name", 617 + "type": "text", 618 + "primaryKey": false, 619 + "notNull": false, 620 + "autoincrement": false, 621 + "default": "''" 622 + }, 623 + "email": { 624 + "name": "email", 625 + "type": "text", 626 + "primaryKey": false, 627 + "notNull": false, 628 + "autoincrement": false, 629 + "default": "''" 630 + }, 631 + "photo_url": { 632 + "name": "photo_url", 633 + "type": "text", 634 + "primaryKey": false, 635 + "notNull": false, 636 + "autoincrement": false, 637 + "default": "''" 638 + }, 639 + "created_at": { 640 + "name": "created_at", 641 + "type": "integer", 642 + "primaryKey": false, 643 + "notNull": false, 644 + "autoincrement": false, 645 + "default": "(strftime('%s', 'now'))" 646 + }, 647 + "updated_at": { 648 + "name": "updated_at", 649 + "type": "integer", 650 + "primaryKey": false, 651 + "notNull": false, 652 + "autoincrement": false, 653 + "default": "(strftime('%s', 'now'))" 654 + } 655 + }, 656 + "indexes": { 657 + "user_tenant_id_unique": { 658 + "name": "user_tenant_id_unique", 659 + "columns": ["tenant_id"], 660 + "isUnique": true 661 + } 662 + }, 663 + "foreignKeys": {}, 664 + "compositePrimaryKeys": {}, 665 + "uniqueConstraints": {} 666 + }, 667 + "users_to_workspaces": { 668 + "name": "users_to_workspaces", 669 + "columns": { 670 + "user_id": { 671 + "name": "user_id", 672 + "type": "integer", 673 + "primaryKey": false, 674 + "notNull": true, 675 + "autoincrement": false 676 + }, 677 + "workspace_id": { 678 + "name": "workspace_id", 679 + "type": "integer", 680 + "primaryKey": false, 681 + "notNull": true, 682 + "autoincrement": false 683 + }, 684 + "role": { 685 + "name": "role", 686 + "type": "text", 687 + "primaryKey": false, 688 + "notNull": true, 689 + "autoincrement": false, 690 + "default": "'member'" 691 + } 692 + }, 693 + "indexes": {}, 694 + "foreignKeys": { 695 + "users_to_workspaces_user_id_user_id_fk": { 696 + "name": "users_to_workspaces_user_id_user_id_fk", 697 + "tableFrom": "users_to_workspaces", 698 + "tableTo": "user", 699 + "columnsFrom": ["user_id"], 700 + "columnsTo": ["id"], 701 + "onDelete": "no action", 702 + "onUpdate": "no action" 703 + }, 704 + "users_to_workspaces_workspace_id_workspace_id_fk": { 705 + "name": "users_to_workspaces_workspace_id_workspace_id_fk", 706 + "tableFrom": "users_to_workspaces", 707 + "tableTo": "workspace", 708 + "columnsFrom": ["workspace_id"], 709 + "columnsTo": ["id"], 710 + "onDelete": "no action", 711 + "onUpdate": "no action" 712 + } 713 + }, 714 + "compositePrimaryKeys": { 715 + "users_to_workspaces_user_id_workspace_id_pk": { 716 + "columns": ["user_id", "workspace_id"] 717 + } 718 + }, 719 + "uniqueConstraints": {} 720 + }, 721 + "page_subscriber": { 722 + "name": "page_subscriber", 723 + "columns": { 724 + "id": { 725 + "name": "id", 726 + "type": "integer", 727 + "primaryKey": true, 728 + "notNull": true, 729 + "autoincrement": false 730 + }, 731 + "email": { 732 + "name": "email", 733 + "type": "text", 734 + "primaryKey": false, 735 + "notNull": true, 736 + "autoincrement": false 737 + }, 738 + "page_id": { 739 + "name": "page_id", 740 + "type": "integer", 741 + "primaryKey": false, 742 + "notNull": true, 743 + "autoincrement": false 744 + }, 745 + "token": { 746 + "name": "token", 747 + "type": "text", 748 + "primaryKey": false, 749 + "notNull": false, 750 + "autoincrement": false 751 + }, 752 + "accepted_at": { 753 + "name": "accepted_at", 754 + "type": "integer", 755 + "primaryKey": false, 756 + "notNull": false, 757 + "autoincrement": false 758 + }, 759 + "expires_at": { 760 + "name": "expires_at", 761 + "type": "integer", 762 + "primaryKey": false, 763 + "notNull": false, 764 + "autoincrement": false 765 + }, 766 + "created_at": { 767 + "name": "created_at", 768 + "type": "integer", 769 + "primaryKey": false, 770 + "notNull": false, 771 + "autoincrement": false, 772 + "default": "(strftime('%s', 'now'))" 773 + }, 774 + "updated_at": { 775 + "name": "updated_at", 776 + "type": "integer", 777 + "primaryKey": false, 778 + "notNull": false, 779 + "autoincrement": false, 780 + "default": "(strftime('%s', 'now'))" 781 + } 782 + }, 783 + "indexes": {}, 784 + "foreignKeys": { 785 + "page_subscriber_page_id_page_id_fk": { 786 + "name": "page_subscriber_page_id_page_id_fk", 787 + "tableFrom": "page_subscriber", 788 + "tableTo": "page", 789 + "columnsFrom": ["page_id"], 790 + "columnsTo": ["id"], 791 + "onDelete": "no action", 792 + "onUpdate": "no action" 793 + } 794 + }, 795 + "compositePrimaryKeys": {}, 796 + "uniqueConstraints": {} 797 + }, 798 + "workspace": { 799 + "name": "workspace", 800 + "columns": { 801 + "id": { 802 + "name": "id", 803 + "type": "integer", 804 + "primaryKey": true, 805 + "notNull": true, 806 + "autoincrement": false 807 + }, 808 + "slug": { 809 + "name": "slug", 810 + "type": "text", 811 + "primaryKey": false, 812 + "notNull": true, 813 + "autoincrement": false 814 + }, 815 + "name": { 816 + "name": "name", 817 + "type": "text", 818 + "primaryKey": false, 819 + "notNull": false, 820 + "autoincrement": false 821 + }, 822 + "stripe_id": { 823 + "name": "stripe_id", 824 + "type": "text(256)", 825 + "primaryKey": false, 826 + "notNull": false, 827 + "autoincrement": false 828 + }, 829 + "subscription_id": { 830 + "name": "subscription_id", 831 + "type": "text", 832 + "primaryKey": false, 833 + "notNull": false, 834 + "autoincrement": false 835 + }, 836 + "plan": { 837 + "name": "plan", 838 + "type": "text", 839 + "primaryKey": false, 840 + "notNull": false, 841 + "autoincrement": false 842 + }, 843 + "ends_at": { 844 + "name": "ends_at", 845 + "type": "integer", 846 + "primaryKey": false, 847 + "notNull": false, 848 + "autoincrement": false 849 + }, 850 + "paid_until": { 851 + "name": "paid_until", 852 + "type": "integer", 853 + "primaryKey": false, 854 + "notNull": false, 855 + "autoincrement": false 856 + }, 857 + "created_at": { 858 + "name": "created_at", 859 + "type": "integer", 860 + "primaryKey": false, 861 + "notNull": false, 862 + "autoincrement": false, 863 + "default": "(strftime('%s', 'now'))" 864 + }, 865 + "updated_at": { 866 + "name": "updated_at", 867 + "type": "integer", 868 + "primaryKey": false, 869 + "notNull": false, 870 + "autoincrement": false, 871 + "default": "(strftime('%s', 'now'))" 872 + } 873 + }, 874 + "indexes": { 875 + "workspace_slug_unique": { 876 + "name": "workspace_slug_unique", 877 + "columns": ["slug"], 878 + "isUnique": true 879 + }, 880 + "workspace_stripe_id_unique": { 881 + "name": "workspace_stripe_id_unique", 882 + "columns": ["stripe_id"], 883 + "isUnique": true 884 + } 885 + }, 886 + "foreignKeys": {}, 887 + "compositePrimaryKeys": {}, 888 + "uniqueConstraints": {} 889 + }, 890 + "notification": { 891 + "name": "notification", 892 + "columns": { 893 + "id": { 894 + "name": "id", 895 + "type": "integer", 896 + "primaryKey": true, 897 + "notNull": true, 898 + "autoincrement": false 899 + }, 900 + "name": { 901 + "name": "name", 902 + "type": "text", 903 + "primaryKey": false, 904 + "notNull": true, 905 + "autoincrement": false 906 + }, 907 + "provider": { 908 + "name": "provider", 909 + "type": "text", 910 + "primaryKey": false, 911 + "notNull": true, 912 + "autoincrement": false 913 + }, 914 + "data": { 915 + "name": "data", 916 + "type": "text", 917 + "primaryKey": false, 918 + "notNull": false, 919 + "autoincrement": false, 920 + "default": "'{}'" 921 + }, 922 + "workspace_id": { 923 + "name": "workspace_id", 924 + "type": "integer", 925 + "primaryKey": false, 926 + "notNull": false, 927 + "autoincrement": false 928 + }, 929 + "created_at": { 930 + "name": "created_at", 931 + "type": "integer", 932 + "primaryKey": false, 933 + "notNull": false, 934 + "autoincrement": false, 935 + "default": "(strftime('%s', 'now'))" 936 + }, 937 + "updated_at": { 938 + "name": "updated_at", 939 + "type": "integer", 940 + "primaryKey": false, 941 + "notNull": false, 942 + "autoincrement": false, 943 + "default": "(strftime('%s', 'now'))" 944 + } 945 + }, 946 + "indexes": {}, 947 + "foreignKeys": { 948 + "notification_workspace_id_workspace_id_fk": { 949 + "name": "notification_workspace_id_workspace_id_fk", 950 + "tableFrom": "notification", 951 + "tableTo": "workspace", 952 + "columnsFrom": ["workspace_id"], 953 + "columnsTo": ["id"], 954 + "onDelete": "no action", 955 + "onUpdate": "no action" 956 + } 957 + }, 958 + "compositePrimaryKeys": {}, 959 + "uniqueConstraints": {} 960 + }, 961 + "notifications_to_monitors": { 962 + "name": "notifications_to_monitors", 963 + "columns": { 964 + "monitor_id": { 965 + "name": "monitor_id", 966 + "type": "integer", 967 + "primaryKey": false, 968 + "notNull": true, 969 + "autoincrement": false 970 + }, 971 + "notification_id": { 972 + "name": "notification_id", 973 + "type": "integer", 974 + "primaryKey": false, 975 + "notNull": true, 976 + "autoincrement": false 977 + } 978 + }, 979 + "indexes": {}, 980 + "foreignKeys": { 981 + "notifications_to_monitors_monitor_id_monitor_id_fk": { 982 + "name": "notifications_to_monitors_monitor_id_monitor_id_fk", 983 + "tableFrom": "notifications_to_monitors", 984 + "tableTo": "monitor", 985 + "columnsFrom": ["monitor_id"], 986 + "columnsTo": ["id"], 987 + "onDelete": "cascade", 988 + "onUpdate": "no action" 989 + }, 990 + "notifications_to_monitors_notification_id_notification_id_fk": { 991 + "name": "notifications_to_monitors_notification_id_notification_id_fk", 992 + "tableFrom": "notifications_to_monitors", 993 + "tableTo": "notification", 994 + "columnsFrom": ["notification_id"], 995 + "columnsTo": ["id"], 996 + "onDelete": "cascade", 997 + "onUpdate": "no action" 998 + } 999 + }, 1000 + "compositePrimaryKeys": { 1001 + "notifications_to_monitors_monitor_id_notification_id_pk": { 1002 + "columns": ["monitor_id", "notification_id"] 1003 + } 1004 + }, 1005 + "uniqueConstraints": {} 1006 + }, 1007 + "monitor_status": { 1008 + "name": "monitor_status", 1009 + "columns": { 1010 + "monitor_id": { 1011 + "name": "monitor_id", 1012 + "type": "integer", 1013 + "primaryKey": false, 1014 + "notNull": true, 1015 + "autoincrement": false 1016 + }, 1017 + "region": { 1018 + "name": "region", 1019 + "type": "text", 1020 + "primaryKey": false, 1021 + "notNull": true, 1022 + "autoincrement": false, 1023 + "default": "''" 1024 + }, 1025 + "status": { 1026 + "name": "status", 1027 + "type": "text", 1028 + "primaryKey": false, 1029 + "notNull": true, 1030 + "autoincrement": false, 1031 + "default": "'active'" 1032 + }, 1033 + "created_at": { 1034 + "name": "created_at", 1035 + "type": "integer", 1036 + "primaryKey": false, 1037 + "notNull": false, 1038 + "autoincrement": false, 1039 + "default": "(strftime('%s', 'now'))" 1040 + }, 1041 + "updated_at": { 1042 + "name": "updated_at", 1043 + "type": "integer", 1044 + "primaryKey": false, 1045 + "notNull": false, 1046 + "autoincrement": false, 1047 + "default": "(strftime('%s', 'now'))" 1048 + } 1049 + }, 1050 + "indexes": { 1051 + "monitor_status_idx": { 1052 + "name": "monitor_status_idx", 1053 + "columns": ["monitor_id", "region"], 1054 + "isUnique": false 1055 + } 1056 + }, 1057 + "foreignKeys": { 1058 + "monitor_status_monitor_id_monitor_id_fk": { 1059 + "name": "monitor_status_monitor_id_monitor_id_fk", 1060 + "tableFrom": "monitor_status", 1061 + "tableTo": "monitor", 1062 + "columnsFrom": ["monitor_id"], 1063 + "columnsTo": ["id"], 1064 + "onDelete": "cascade", 1065 + "onUpdate": "no action" 1066 + } 1067 + }, 1068 + "compositePrimaryKeys": { 1069 + "monitor_status_monitor_id_region_pk": { 1070 + "columns": ["monitor_id", "region"] 1071 + } 1072 + }, 1073 + "uniqueConstraints": {} 1074 + }, 1075 + "invitation": { 1076 + "name": "invitation", 1077 + "columns": { 1078 + "id": { 1079 + "name": "id", 1080 + "type": "integer", 1081 + "primaryKey": true, 1082 + "notNull": true, 1083 + "autoincrement": false 1084 + }, 1085 + "email": { 1086 + "name": "email", 1087 + "type": "text", 1088 + "primaryKey": false, 1089 + "notNull": true, 1090 + "autoincrement": false 1091 + }, 1092 + "role": { 1093 + "name": "role", 1094 + "type": "text", 1095 + "primaryKey": false, 1096 + "notNull": true, 1097 + "autoincrement": false, 1098 + "default": "'member'" 1099 + }, 1100 + "workspace_id": { 1101 + "name": "workspace_id", 1102 + "type": "integer", 1103 + "primaryKey": false, 1104 + "notNull": true, 1105 + "autoincrement": false 1106 + }, 1107 + "token": { 1108 + "name": "token", 1109 + "type": "text", 1110 + "primaryKey": false, 1111 + "notNull": true, 1112 + "autoincrement": false 1113 + }, 1114 + "expires_at": { 1115 + "name": "expires_at", 1116 + "type": "integer", 1117 + "primaryKey": false, 1118 + "notNull": true, 1119 + "autoincrement": false 1120 + }, 1121 + "created_at": { 1122 + "name": "created_at", 1123 + "type": "integer", 1124 + "primaryKey": false, 1125 + "notNull": false, 1126 + "autoincrement": false, 1127 + "default": "(strftime('%s', 'now'))" 1128 + }, 1129 + "accepted_at": { 1130 + "name": "accepted_at", 1131 + "type": "integer", 1132 + "primaryKey": false, 1133 + "notNull": false, 1134 + "autoincrement": false 1135 + } 1136 + }, 1137 + "indexes": {}, 1138 + "foreignKeys": {}, 1139 + "compositePrimaryKeys": {}, 1140 + "uniqueConstraints": {} 1141 + }, 1142 + "incident": { 1143 + "name": "incident", 1144 + "columns": { 1145 + "id": { 1146 + "name": "id", 1147 + "type": "integer", 1148 + "primaryKey": true, 1149 + "notNull": true, 1150 + "autoincrement": false 1151 + }, 1152 + "title": { 1153 + "name": "title", 1154 + "type": "text", 1155 + "primaryKey": false, 1156 + "notNull": true, 1157 + "autoincrement": false, 1158 + "default": "''" 1159 + }, 1160 + "summary": { 1161 + "name": "summary", 1162 + "type": "text", 1163 + "primaryKey": false, 1164 + "notNull": true, 1165 + "autoincrement": false, 1166 + "default": "''" 1167 + }, 1168 + "status": { 1169 + "name": "status", 1170 + "type": "text", 1171 + "primaryKey": false, 1172 + "notNull": true, 1173 + "autoincrement": false, 1174 + "default": "'triage'" 1175 + }, 1176 + "monitor_id": { 1177 + "name": "monitor_id", 1178 + "type": "integer", 1179 + "primaryKey": false, 1180 + "notNull": false, 1181 + "autoincrement": false 1182 + }, 1183 + "workspace_id": { 1184 + "name": "workspace_id", 1185 + "type": "integer", 1186 + "primaryKey": false, 1187 + "notNull": false, 1188 + "autoincrement": false 1189 + }, 1190 + "started_at": { 1191 + "name": "started_at", 1192 + "type": "integer", 1193 + "primaryKey": false, 1194 + "notNull": true, 1195 + "autoincrement": false, 1196 + "default": "(strftime('%s', 'now'))" 1197 + }, 1198 + "acknowledged_at": { 1199 + "name": "acknowledged_at", 1200 + "type": "integer", 1201 + "primaryKey": false, 1202 + "notNull": false, 1203 + "autoincrement": false 1204 + }, 1205 + "acknowledged_by": { 1206 + "name": "acknowledged_by", 1207 + "type": "integer", 1208 + "primaryKey": false, 1209 + "notNull": false, 1210 + "autoincrement": false 1211 + }, 1212 + "resolved_at": { 1213 + "name": "resolved_at", 1214 + "type": "integer", 1215 + "primaryKey": false, 1216 + "notNull": false, 1217 + "autoincrement": false 1218 + }, 1219 + "resolved_by": { 1220 + "name": "resolved_by", 1221 + "type": "integer", 1222 + "primaryKey": false, 1223 + "notNull": false, 1224 + "autoincrement": false 1225 + }, 1226 + "created_at": { 1227 + "name": "created_at", 1228 + "type": "integer", 1229 + "primaryKey": false, 1230 + "notNull": false, 1231 + "autoincrement": false, 1232 + "default": "(strftime('%s', 'now'))" 1233 + }, 1234 + "updated_at": { 1235 + "name": "updated_at", 1236 + "type": "integer", 1237 + "primaryKey": false, 1238 + "notNull": false, 1239 + "autoincrement": false, 1240 + "default": "(strftime('%s', 'now'))" 1241 + } 1242 + }, 1243 + "indexes": { 1244 + "incident_monitor_id_started_at_unique": { 1245 + "name": "incident_monitor_id_started_at_unique", 1246 + "columns": ["monitor_id", "started_at"], 1247 + "isUnique": true 1248 + } 1249 + }, 1250 + "foreignKeys": { 1251 + "incident_monitor_id_monitor_id_fk": { 1252 + "name": "incident_monitor_id_monitor_id_fk", 1253 + "tableFrom": "incident", 1254 + "tableTo": "monitor", 1255 + "columnsFrom": ["monitor_id"], 1256 + "columnsTo": ["id"], 1257 + "onDelete": "set default", 1258 + "onUpdate": "no action" 1259 + }, 1260 + "incident_workspace_id_workspace_id_fk": { 1261 + "name": "incident_workspace_id_workspace_id_fk", 1262 + "tableFrom": "incident", 1263 + "tableTo": "workspace", 1264 + "columnsFrom": ["workspace_id"], 1265 + "columnsTo": ["id"], 1266 + "onDelete": "no action", 1267 + "onUpdate": "no action" 1268 + }, 1269 + "incident_acknowledged_by_user_id_fk": { 1270 + "name": "incident_acknowledged_by_user_id_fk", 1271 + "tableFrom": "incident", 1272 + "tableTo": "user", 1273 + "columnsFrom": ["acknowledged_by"], 1274 + "columnsTo": ["id"], 1275 + "onDelete": "no action", 1276 + "onUpdate": "no action" 1277 + }, 1278 + "incident_resolved_by_user_id_fk": { 1279 + "name": "incident_resolved_by_user_id_fk", 1280 + "tableFrom": "incident", 1281 + "tableTo": "user", 1282 + "columnsFrom": ["resolved_by"], 1283 + "columnsTo": ["id"], 1284 + "onDelete": "no action", 1285 + "onUpdate": "no action" 1286 + } 1287 + }, 1288 + "compositePrimaryKeys": {}, 1289 + "uniqueConstraints": {} 1290 + } 1291 + }, 1292 + "enums": {}, 1293 + "_meta": { 1294 + "schemas": {}, 1295 + "tables": {}, 1296 + "columns": {} 1297 + } 1298 + }
+8 -1
packages/db/drizzle/meta/_journal.json
··· 113 113 "when": 1705856545397, 114 114 "tag": "0015_bent_sister_grimm", 115 115 "breakpoints": true 116 + }, 117 + { 118 + "idx": 16, 119 + "version": "5", 120 + "when": 1706111184826, 121 + "tag": "0016_certain_praxagora", 122 + "breakpoints": true 116 123 } 117 124 ] 118 - } 125 + }
+45 -25
packages/db/src/schema/incidents/incident.ts
··· 1 1 import { sql } from "drizzle-orm"; 2 - import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; 2 + import { 3 + integer, 4 + primaryKey, 5 + sqliteTable, 6 + text, 7 + unique, 8 + } from "drizzle-orm/sqlite-core"; 3 9 4 10 import { monitor } from "../monitors"; 5 11 import { user } from "../users/user"; ··· 14 20 "duplicated", 15 21 ] as const; 16 22 17 - export const incidentTable = sqliteTable("incident", { 18 - id: integer("id").primaryKey(), 19 - title: text("title").default("").notNull(), 20 - summary: text("summary").default("").notNull(), 21 - status: text("status", { enum: statusIncident }).default("triage").notNull(), 23 + export const incidentTable = sqliteTable( 24 + "incident", 25 + { 26 + id: integer("id").primaryKey(), 27 + title: text("title").default("").notNull(), 28 + summary: text("summary").default("").notNull(), 29 + status: text("status", { enum: statusIncident }) 30 + .default("triage") 31 + .notNull(), 22 32 23 - // Service affected by incident 24 - monitorId: integer("monitor_id").references(() => monitor.id), 33 + // Service affected by incident 34 + monitorId: integer("monitor_id").references(() => monitor.id, { 35 + onDelete: "set default", 36 + }), 25 37 26 - // Workspace where the incident happened 27 - workspaceId: integer("workspace_id").references(() => workspace.id), 28 - // Data related to incident timeline 29 - startedAt: integer("started_at", { mode: "timestamp" }), 30 - // Who has acknoledge the incident 31 - acknowledgedAt: integer("acknowledged_at", { mode: "timestamp" }), 32 - acknowledgedBy: integer("acknowledged_by").references(() => user.id), 38 + // Workspace where the incident happened 39 + workspaceId: integer("workspace_id").references(() => workspace.id), 40 + // Data related to incident timeline 41 + startedAt: integer("started_at", { mode: "timestamp" }) 42 + .notNull() 43 + .default(sql`(strftime('%s', 'now'))`), 44 + // Who has acknoledge the incident 45 + acknowledgedAt: integer("acknowledged_at", { mode: "timestamp" }), 46 + acknowledgedBy: integer("acknowledged_by").references(() => user.id), 33 47 34 - // Who has resolved it 35 - resolvedAt: integer("resolved_at", { mode: "timestamp" }), 36 - resolvedBy: integer("resolved_by").references(() => user.id), 48 + // Who has resolved it 49 + resolvedAt: integer("resolved_at", { mode: "timestamp" }), 50 + resolvedBy: integer("resolved_by").references(() => user.id), 37 51 38 - createdAt: integer("created_at", { mode: "timestamp" }).default( 39 - sql`(strftime('%s', 'now'))`, 40 - ), 41 - updatedAt: integer("updated_at", { mode: "timestamp" }).default( 42 - sql`(strftime('%s', 'now'))`, 43 - ), 44 - }); 52 + createdAt: integer("created_at", { mode: "timestamp" }).default( 53 + sql`(strftime('%s', 'now'))`, 54 + ), 55 + updatedAt: integer("updated_at", { mode: "timestamp" }).default( 56 + sql`(strftime('%s', 'now'))`, 57 + ), 58 + }, 59 + (table) => { 60 + return { 61 + unique: unique().on(table.monitorId, table.startedAt), 62 + }; 63 + }, 64 + );