A social knowledge tool for researchers built on ATProto

add custom migration to clear db

+784
+10
src/shared/infrastructure/database/migrations/0005_truncate-tables.sql
··· 1 + -- Custom SQL migration file, put your code below! -- 2 + -- Truncate all tables to wipe data but keep table structure 3 + -- CASCADE ensures foreign key constraints don't prevent truncation 4 + TRUNCATE TABLE "collection_cards", 5 + "collection_collaborators", 6 + "library_memberships", 7 + "collections", 8 + "cards", 9 + "published_records", 10 + "feed_activities" CASCADE;
+767
src/shared/infrastructure/database/migrations/meta/0005_snapshot.json
··· 1 + { 2 + "id": "2d3157fe-869f-46ed-bcdc-03fc757f16c1", 3 + "prevId": "1e15b3e8-04ba-4e0a-965e-07142597ddc4", 4 + "version": "7", 5 + "dialect": "postgresql", 6 + "tables": { 7 + "public.app_password_sessions": { 8 + "name": "app_password_sessions", 9 + "schema": "", 10 + "columns": { 11 + "did": { 12 + "name": "did", 13 + "type": "text", 14 + "primaryKey": true, 15 + "notNull": true 16 + }, 17 + "session_data": { 18 + "name": "session_data", 19 + "type": "jsonb", 20 + "primaryKey": false, 21 + "notNull": true 22 + }, 23 + "app_password": { 24 + "name": "app_password", 25 + "type": "text", 26 + "primaryKey": false, 27 + "notNull": true 28 + }, 29 + "created_at": { 30 + "name": "created_at", 31 + "type": "timestamp", 32 + "primaryKey": false, 33 + "notNull": false, 34 + "default": "now()" 35 + }, 36 + "updated_at": { 37 + "name": "updated_at", 38 + "type": "timestamp", 39 + "primaryKey": false, 40 + "notNull": false, 41 + "default": "now()" 42 + } 43 + }, 44 + "indexes": {}, 45 + "foreignKeys": {}, 46 + "compositePrimaryKeys": {}, 47 + "uniqueConstraints": {}, 48 + "policies": {}, 49 + "checkConstraints": {}, 50 + "isRLSEnabled": false 51 + }, 52 + "public.cards": { 53 + "name": "cards", 54 + "schema": "", 55 + "columns": { 56 + "id": { 57 + "name": "id", 58 + "type": "uuid", 59 + "primaryKey": true, 60 + "notNull": true 61 + }, 62 + "author_id": { 63 + "name": "author_id", 64 + "type": "text", 65 + "primaryKey": false, 66 + "notNull": true 67 + }, 68 + "type": { 69 + "name": "type", 70 + "type": "text", 71 + "primaryKey": false, 72 + "notNull": true 73 + }, 74 + "content_data": { 75 + "name": "content_data", 76 + "type": "jsonb", 77 + "primaryKey": false, 78 + "notNull": true 79 + }, 80 + "url": { 81 + "name": "url", 82 + "type": "text", 83 + "primaryKey": false, 84 + "notNull": false 85 + }, 86 + "parent_card_id": { 87 + "name": "parent_card_id", 88 + "type": "uuid", 89 + "primaryKey": false, 90 + "notNull": false 91 + }, 92 + "published_record_id": { 93 + "name": "published_record_id", 94 + "type": "uuid", 95 + "primaryKey": false, 96 + "notNull": false 97 + }, 98 + "library_count": { 99 + "name": "library_count", 100 + "type": "integer", 101 + "primaryKey": false, 102 + "notNull": true, 103 + "default": 0 104 + }, 105 + "created_at": { 106 + "name": "created_at", 107 + "type": "timestamp", 108 + "primaryKey": false, 109 + "notNull": true, 110 + "default": "now()" 111 + }, 112 + "updated_at": { 113 + "name": "updated_at", 114 + "type": "timestamp", 115 + "primaryKey": false, 116 + "notNull": true, 117 + "default": "now()" 118 + } 119 + }, 120 + "indexes": {}, 121 + "foreignKeys": { 122 + "cards_parent_card_id_cards_id_fk": { 123 + "name": "cards_parent_card_id_cards_id_fk", 124 + "tableFrom": "cards", 125 + "columnsFrom": [ 126 + "parent_card_id" 127 + ], 128 + "tableTo": "cards", 129 + "columnsTo": [ 130 + "id" 131 + ], 132 + "onUpdate": "no action", 133 + "onDelete": "no action" 134 + }, 135 + "cards_published_record_id_published_records_id_fk": { 136 + "name": "cards_published_record_id_published_records_id_fk", 137 + "tableFrom": "cards", 138 + "columnsFrom": [ 139 + "published_record_id" 140 + ], 141 + "tableTo": "published_records", 142 + "columnsTo": [ 143 + "id" 144 + ], 145 + "onUpdate": "no action", 146 + "onDelete": "no action" 147 + } 148 + }, 149 + "compositePrimaryKeys": {}, 150 + "uniqueConstraints": {}, 151 + "policies": {}, 152 + "checkConstraints": {}, 153 + "isRLSEnabled": false 154 + }, 155 + "public.collection_cards": { 156 + "name": "collection_cards", 157 + "schema": "", 158 + "columns": { 159 + "id": { 160 + "name": "id", 161 + "type": "uuid", 162 + "primaryKey": true, 163 + "notNull": true 164 + }, 165 + "collection_id": { 166 + "name": "collection_id", 167 + "type": "uuid", 168 + "primaryKey": false, 169 + "notNull": true 170 + }, 171 + "card_id": { 172 + "name": "card_id", 173 + "type": "uuid", 174 + "primaryKey": false, 175 + "notNull": true 176 + }, 177 + "added_by": { 178 + "name": "added_by", 179 + "type": "text", 180 + "primaryKey": false, 181 + "notNull": true 182 + }, 183 + "added_at": { 184 + "name": "added_at", 185 + "type": "timestamp", 186 + "primaryKey": false, 187 + "notNull": true, 188 + "default": "now()" 189 + }, 190 + "published_record_id": { 191 + "name": "published_record_id", 192 + "type": "uuid", 193 + "primaryKey": false, 194 + "notNull": false 195 + } 196 + }, 197 + "indexes": {}, 198 + "foreignKeys": { 199 + "collection_cards_collection_id_collections_id_fk": { 200 + "name": "collection_cards_collection_id_collections_id_fk", 201 + "tableFrom": "collection_cards", 202 + "columnsFrom": [ 203 + "collection_id" 204 + ], 205 + "tableTo": "collections", 206 + "columnsTo": [ 207 + "id" 208 + ], 209 + "onUpdate": "no action", 210 + "onDelete": "cascade" 211 + }, 212 + "collection_cards_card_id_cards_id_fk": { 213 + "name": "collection_cards_card_id_cards_id_fk", 214 + "tableFrom": "collection_cards", 215 + "columnsFrom": [ 216 + "card_id" 217 + ], 218 + "tableTo": "cards", 219 + "columnsTo": [ 220 + "id" 221 + ], 222 + "onUpdate": "no action", 223 + "onDelete": "cascade" 224 + }, 225 + "collection_cards_published_record_id_published_records_id_fk": { 226 + "name": "collection_cards_published_record_id_published_records_id_fk", 227 + "tableFrom": "collection_cards", 228 + "columnsFrom": [ 229 + "published_record_id" 230 + ], 231 + "tableTo": "published_records", 232 + "columnsTo": [ 233 + "id" 234 + ], 235 + "onUpdate": "no action", 236 + "onDelete": "no action" 237 + } 238 + }, 239 + "compositePrimaryKeys": {}, 240 + "uniqueConstraints": {}, 241 + "policies": {}, 242 + "checkConstraints": {}, 243 + "isRLSEnabled": false 244 + }, 245 + "public.collection_collaborators": { 246 + "name": "collection_collaborators", 247 + "schema": "", 248 + "columns": { 249 + "id": { 250 + "name": "id", 251 + "type": "uuid", 252 + "primaryKey": true, 253 + "notNull": true 254 + }, 255 + "collection_id": { 256 + "name": "collection_id", 257 + "type": "uuid", 258 + "primaryKey": false, 259 + "notNull": true 260 + }, 261 + "collaborator_id": { 262 + "name": "collaborator_id", 263 + "type": "text", 264 + "primaryKey": false, 265 + "notNull": true 266 + } 267 + }, 268 + "indexes": {}, 269 + "foreignKeys": { 270 + "collection_collaborators_collection_id_collections_id_fk": { 271 + "name": "collection_collaborators_collection_id_collections_id_fk", 272 + "tableFrom": "collection_collaborators", 273 + "columnsFrom": [ 274 + "collection_id" 275 + ], 276 + "tableTo": "collections", 277 + "columnsTo": [ 278 + "id" 279 + ], 280 + "onUpdate": "no action", 281 + "onDelete": "cascade" 282 + } 283 + }, 284 + "compositePrimaryKeys": {}, 285 + "uniqueConstraints": {}, 286 + "policies": {}, 287 + "checkConstraints": {}, 288 + "isRLSEnabled": false 289 + }, 290 + "public.collections": { 291 + "name": "collections", 292 + "schema": "", 293 + "columns": { 294 + "id": { 295 + "name": "id", 296 + "type": "uuid", 297 + "primaryKey": true, 298 + "notNull": true 299 + }, 300 + "author_id": { 301 + "name": "author_id", 302 + "type": "text", 303 + "primaryKey": false, 304 + "notNull": true 305 + }, 306 + "name": { 307 + "name": "name", 308 + "type": "text", 309 + "primaryKey": false, 310 + "notNull": true 311 + }, 312 + "description": { 313 + "name": "description", 314 + "type": "text", 315 + "primaryKey": false, 316 + "notNull": false 317 + }, 318 + "access_type": { 319 + "name": "access_type", 320 + "type": "text", 321 + "primaryKey": false, 322 + "notNull": true 323 + }, 324 + "card_count": { 325 + "name": "card_count", 326 + "type": "integer", 327 + "primaryKey": false, 328 + "notNull": true, 329 + "default": 0 330 + }, 331 + "created_at": { 332 + "name": "created_at", 333 + "type": "timestamp", 334 + "primaryKey": false, 335 + "notNull": true, 336 + "default": "now()" 337 + }, 338 + "updated_at": { 339 + "name": "updated_at", 340 + "type": "timestamp", 341 + "primaryKey": false, 342 + "notNull": true, 343 + "default": "now()" 344 + }, 345 + "published_record_id": { 346 + "name": "published_record_id", 347 + "type": "uuid", 348 + "primaryKey": false, 349 + "notNull": false 350 + } 351 + }, 352 + "indexes": {}, 353 + "foreignKeys": { 354 + "collections_published_record_id_published_records_id_fk": { 355 + "name": "collections_published_record_id_published_records_id_fk", 356 + "tableFrom": "collections", 357 + "columnsFrom": [ 358 + "published_record_id" 359 + ], 360 + "tableTo": "published_records", 361 + "columnsTo": [ 362 + "id" 363 + ], 364 + "onUpdate": "no action", 365 + "onDelete": "no action" 366 + } 367 + }, 368 + "compositePrimaryKeys": {}, 369 + "uniqueConstraints": {}, 370 + "policies": {}, 371 + "checkConstraints": {}, 372 + "isRLSEnabled": false 373 + }, 374 + "public.library_memberships": { 375 + "name": "library_memberships", 376 + "schema": "", 377 + "columns": { 378 + "card_id": { 379 + "name": "card_id", 380 + "type": "uuid", 381 + "primaryKey": false, 382 + "notNull": true 383 + }, 384 + "user_id": { 385 + "name": "user_id", 386 + "type": "text", 387 + "primaryKey": false, 388 + "notNull": true 389 + }, 390 + "added_at": { 391 + "name": "added_at", 392 + "type": "timestamp", 393 + "primaryKey": false, 394 + "notNull": true, 395 + "default": "now()" 396 + }, 397 + "published_record_id": { 398 + "name": "published_record_id", 399 + "type": "uuid", 400 + "primaryKey": false, 401 + "notNull": false 402 + } 403 + }, 404 + "indexes": { 405 + "idx_user_cards": { 406 + "name": "idx_user_cards", 407 + "columns": [ 408 + { 409 + "expression": "user_id", 410 + "isExpression": false, 411 + "asc": true, 412 + "nulls": "last" 413 + } 414 + ], 415 + "isUnique": false, 416 + "with": {}, 417 + "method": "btree", 418 + "concurrently": false 419 + }, 420 + "idx_card_users": { 421 + "name": "idx_card_users", 422 + "columns": [ 423 + { 424 + "expression": "card_id", 425 + "isExpression": false, 426 + "asc": true, 427 + "nulls": "last" 428 + } 429 + ], 430 + "isUnique": false, 431 + "with": {}, 432 + "method": "btree", 433 + "concurrently": false 434 + } 435 + }, 436 + "foreignKeys": { 437 + "library_memberships_card_id_cards_id_fk": { 438 + "name": "library_memberships_card_id_cards_id_fk", 439 + "tableFrom": "library_memberships", 440 + "columnsFrom": [ 441 + "card_id" 442 + ], 443 + "tableTo": "cards", 444 + "columnsTo": [ 445 + "id" 446 + ], 447 + "onUpdate": "no action", 448 + "onDelete": "cascade" 449 + }, 450 + "library_memberships_published_record_id_published_records_id_fk": { 451 + "name": "library_memberships_published_record_id_published_records_id_fk", 452 + "tableFrom": "library_memberships", 453 + "columnsFrom": [ 454 + "published_record_id" 455 + ], 456 + "tableTo": "published_records", 457 + "columnsTo": [ 458 + "id" 459 + ], 460 + "onUpdate": "no action", 461 + "onDelete": "no action" 462 + } 463 + }, 464 + "compositePrimaryKeys": { 465 + "library_memberships_card_id_user_id_pk": { 466 + "name": "library_memberships_card_id_user_id_pk", 467 + "columns": [ 468 + "card_id", 469 + "user_id" 470 + ] 471 + } 472 + }, 473 + "uniqueConstraints": {}, 474 + "policies": {}, 475 + "checkConstraints": {}, 476 + "isRLSEnabled": false 477 + }, 478 + "public.published_records": { 479 + "name": "published_records", 480 + "schema": "", 481 + "columns": { 482 + "id": { 483 + "name": "id", 484 + "type": "uuid", 485 + "primaryKey": true, 486 + "notNull": true 487 + }, 488 + "uri": { 489 + "name": "uri", 490 + "type": "text", 491 + "primaryKey": false, 492 + "notNull": true 493 + }, 494 + "cid": { 495 + "name": "cid", 496 + "type": "text", 497 + "primaryKey": false, 498 + "notNull": true 499 + }, 500 + "recorded_at": { 501 + "name": "recorded_at", 502 + "type": "timestamp", 503 + "primaryKey": false, 504 + "notNull": true, 505 + "default": "now()" 506 + } 507 + }, 508 + "indexes": { 509 + "uri_cid_unique_idx": { 510 + "name": "uri_cid_unique_idx", 511 + "columns": [ 512 + { 513 + "expression": "uri", 514 + "isExpression": false, 515 + "asc": true, 516 + "nulls": "last" 517 + }, 518 + { 519 + "expression": "cid", 520 + "isExpression": false, 521 + "asc": true, 522 + "nulls": "last" 523 + } 524 + ], 525 + "isUnique": true, 526 + "with": {}, 527 + "method": "btree", 528 + "concurrently": false 529 + }, 530 + "published_records_uri_idx": { 531 + "name": "published_records_uri_idx", 532 + "columns": [ 533 + { 534 + "expression": "uri", 535 + "isExpression": false, 536 + "asc": true, 537 + "nulls": "last" 538 + } 539 + ], 540 + "isUnique": false, 541 + "with": {}, 542 + "method": "btree", 543 + "concurrently": false 544 + } 545 + }, 546 + "foreignKeys": {}, 547 + "compositePrimaryKeys": {}, 548 + "uniqueConstraints": {}, 549 + "policies": {}, 550 + "checkConstraints": {}, 551 + "isRLSEnabled": false 552 + }, 553 + "public.feed_activities": { 554 + "name": "feed_activities", 555 + "schema": "", 556 + "columns": { 557 + "id": { 558 + "name": "id", 559 + "type": "uuid", 560 + "primaryKey": true, 561 + "notNull": true 562 + }, 563 + "actor_id": { 564 + "name": "actor_id", 565 + "type": "text", 566 + "primaryKey": false, 567 + "notNull": true 568 + }, 569 + "type": { 570 + "name": "type", 571 + "type": "text", 572 + "primaryKey": false, 573 + "notNull": true 574 + }, 575 + "metadata": { 576 + "name": "metadata", 577 + "type": "jsonb", 578 + "primaryKey": false, 579 + "notNull": true 580 + }, 581 + "created_at": { 582 + "name": "created_at", 583 + "type": "timestamp", 584 + "primaryKey": false, 585 + "notNull": true, 586 + "default": "now()" 587 + } 588 + }, 589 + "indexes": {}, 590 + "foreignKeys": {}, 591 + "compositePrimaryKeys": {}, 592 + "uniqueConstraints": {}, 593 + "policies": {}, 594 + "checkConstraints": {}, 595 + "isRLSEnabled": false 596 + }, 597 + "public.auth_session": { 598 + "name": "auth_session", 599 + "schema": "", 600 + "columns": { 601 + "key": { 602 + "name": "key", 603 + "type": "text", 604 + "primaryKey": true, 605 + "notNull": true 606 + }, 607 + "session": { 608 + "name": "session", 609 + "type": "text", 610 + "primaryKey": false, 611 + "notNull": true 612 + } 613 + }, 614 + "indexes": {}, 615 + "foreignKeys": {}, 616 + "compositePrimaryKeys": {}, 617 + "uniqueConstraints": {}, 618 + "policies": {}, 619 + "checkConstraints": {}, 620 + "isRLSEnabled": false 621 + }, 622 + "public.auth_state": { 623 + "name": "auth_state", 624 + "schema": "", 625 + "columns": { 626 + "key": { 627 + "name": "key", 628 + "type": "text", 629 + "primaryKey": true, 630 + "notNull": true 631 + }, 632 + "state": { 633 + "name": "state", 634 + "type": "text", 635 + "primaryKey": false, 636 + "notNull": true 637 + }, 638 + "created_at": { 639 + "name": "created_at", 640 + "type": "timestamp", 641 + "primaryKey": false, 642 + "notNull": false, 643 + "default": "now()" 644 + } 645 + }, 646 + "indexes": {}, 647 + "foreignKeys": {}, 648 + "compositePrimaryKeys": {}, 649 + "uniqueConstraints": {}, 650 + "policies": {}, 651 + "checkConstraints": {}, 652 + "isRLSEnabled": false 653 + }, 654 + "public.auth_refresh_tokens": { 655 + "name": "auth_refresh_tokens", 656 + "schema": "", 657 + "columns": { 658 + "token_id": { 659 + "name": "token_id", 660 + "type": "text", 661 + "primaryKey": true, 662 + "notNull": true 663 + }, 664 + "user_did": { 665 + "name": "user_did", 666 + "type": "text", 667 + "primaryKey": false, 668 + "notNull": true 669 + }, 670 + "refresh_token": { 671 + "name": "refresh_token", 672 + "type": "text", 673 + "primaryKey": false, 674 + "notNull": true 675 + }, 676 + "issued_at": { 677 + "name": "issued_at", 678 + "type": "timestamp", 679 + "primaryKey": false, 680 + "notNull": true 681 + }, 682 + "expires_at": { 683 + "name": "expires_at", 684 + "type": "timestamp", 685 + "primaryKey": false, 686 + "notNull": true 687 + }, 688 + "revoked": { 689 + "name": "revoked", 690 + "type": "boolean", 691 + "primaryKey": false, 692 + "notNull": false, 693 + "default": false 694 + } 695 + }, 696 + "indexes": {}, 697 + "foreignKeys": { 698 + "auth_refresh_tokens_user_did_users_id_fk": { 699 + "name": "auth_refresh_tokens_user_did_users_id_fk", 700 + "tableFrom": "auth_refresh_tokens", 701 + "columnsFrom": [ 702 + "user_did" 703 + ], 704 + "tableTo": "users", 705 + "columnsTo": [ 706 + "id" 707 + ], 708 + "onUpdate": "no action", 709 + "onDelete": "no action" 710 + } 711 + }, 712 + "compositePrimaryKeys": {}, 713 + "uniqueConstraints": {}, 714 + "policies": {}, 715 + "checkConstraints": {}, 716 + "isRLSEnabled": false 717 + }, 718 + "public.users": { 719 + "name": "users", 720 + "schema": "", 721 + "columns": { 722 + "id": { 723 + "name": "id", 724 + "type": "text", 725 + "primaryKey": true, 726 + "notNull": true 727 + }, 728 + "handle": { 729 + "name": "handle", 730 + "type": "text", 731 + "primaryKey": false, 732 + "notNull": false 733 + }, 734 + "linked_at": { 735 + "name": "linked_at", 736 + "type": "timestamp", 737 + "primaryKey": false, 738 + "notNull": true 739 + }, 740 + "last_login_at": { 741 + "name": "last_login_at", 742 + "type": "timestamp", 743 + "primaryKey": false, 744 + "notNull": true 745 + } 746 + }, 747 + "indexes": {}, 748 + "foreignKeys": {}, 749 + "compositePrimaryKeys": {}, 750 + "uniqueConstraints": {}, 751 + "policies": {}, 752 + "checkConstraints": {}, 753 + "isRLSEnabled": false 754 + } 755 + }, 756 + "enums": {}, 757 + "schemas": {}, 758 + "views": {}, 759 + "sequences": {}, 760 + "roles": {}, 761 + "policies": {}, 762 + "_meta": { 763 + "columns": {}, 764 + "schemas": {}, 765 + "tables": {} 766 + } 767 + }
+7
src/shared/infrastructure/database/migrations/meta/_journal.json
··· 36 36 "when": 1759875361391, 37 37 "tag": "0004_brainy_rocket_racer", 38 38 "breakpoints": true 39 + }, 40 + { 41 + "idx": 5, 42 + "version": "7", 43 + "when": 1759957391430, 44 + "tag": "0005_truncate-tables", 45 + "breakpoints": true 39 46 } 40 47 ] 41 48 }