using System; using System.Collections.Generic; using DysonNetwork.Shared.Models; using Microsoft.EntityFrameworkCore.Migrations; using NodaTime; #nullable disable namespace DysonNetwork.Sphere.Migrations { /// public partial class AddActivityPub : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn>( name: "meta", table: "publishers", type: "jsonb", nullable: true); migrationBuilder.AddColumn( name: "private_key_pem", table: "publishers", type: "character varying(8192)", maxLength: 8192, nullable: true); migrationBuilder.AddColumn( name: "public_key_pem", table: "publishers", type: "character varying(8192)", maxLength: 8192, nullable: true); migrationBuilder.CreateTable( name: "fediverse_instances", columns: table => new { id = table.Column(type: "uuid", nullable: false), domain = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), name = table.Column(type: "character varying(512)", maxLength: 512, nullable: true), description = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true), software = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), version = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), metadata = table.Column>(type: "jsonb", nullable: true), is_blocked = table.Column(type: "boolean", nullable: false), is_silenced = table.Column(type: "boolean", nullable: false), block_reason = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), last_fetched_at = table.Column(type: "timestamp with time zone", nullable: true), last_activity_at = table.Column(type: "timestamp with time zone", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false), updated_at = table.Column(type: "timestamp with time zone", nullable: false), deleted_at = table.Column(type: "timestamp with time zone", nullable: true), active_users = table.Column(type: "integer", nullable: true), contact_account_username = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), contact_email = table.Column(type: "character varying(512)", maxLength: 512, nullable: true), icon_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), metadata_fetched_at = table.Column(type: "timestamp with time zone", nullable: true), thumbnail_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true) }, constraints: table => { table.PrimaryKey("pk_fediverse_instances", x => x.id); }); migrationBuilder.CreateTable( name: "fediverse_actors", columns: table => new { id = table.Column(type: "uuid", nullable: false), uri = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false), username = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), display_name = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), bio = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true), inbox_uri = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), outbox_uri = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), followers_uri = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), following_uri = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), featured_uri = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), public_key_id = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), public_key = table.Column(type: "character varying(8192)", maxLength: 8192, nullable: true), metadata = table.Column>(type: "jsonb", nullable: true), avatar_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), header_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), is_bot = table.Column(type: "boolean", nullable: false), is_locked = table.Column(type: "boolean", nullable: false), is_discoverable = table.Column(type: "boolean", nullable: false), instance_id = table.Column(type: "uuid", nullable: false), last_fetched_at = table.Column(type: "timestamp with time zone", nullable: true), last_activity_at = table.Column(type: "timestamp with time zone", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false), updated_at = table.Column(type: "timestamp with time zone", nullable: false), deleted_at = table.Column(type: "timestamp with time zone", nullable: true), type = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false, defaultValue: "Person"), publisher_id = table.Column(type: "uuid", nullable: true) }, constraints: table => { table.PrimaryKey("pk_fediverse_actors", x => x.id); table.ForeignKey( name: "fk_fediverse_actors_fediverse_instances_instance_id", column: x => x.instance_id, principalTable: "fediverse_instances", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "fediverse_relationships", columns: table => new { id = table.Column(type: "uuid", nullable: false), actor_id = table.Column(type: "uuid", nullable: false), target_actor_id = table.Column(type: "uuid", nullable: false), state = table.Column(type: "integer", nullable: false), is_muting = table.Column(type: "boolean", nullable: false), is_blocking = table.Column(type: "boolean", nullable: false), followed_at = table.Column(type: "timestamp with time zone", nullable: true), followed_back_at = table.Column(type: "timestamp with time zone", nullable: true), reject_reason = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false), updated_at = table.Column(type: "timestamp with time zone", nullable: false), deleted_at = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("pk_fediverse_relationships", x => x.id); table.ForeignKey( name: "fk_fediverse_relationships_fediverse_actors_actor_id", column: x => x.actor_id, principalTable: "fediverse_actors", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_fediverse_relationships_fediverse_actors_target_actor_id", column: x => x.target_actor_id, principalTable: "fediverse_actors", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "activity_pub_deliveries", columns: table => new { id = table.Column(type: "uuid", nullable: false), activity_id = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false), activity_type = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), inbox_uri = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false), actor_uri = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false), status = table.Column(type: "integer", nullable: false), retry_count = table.Column(type: "integer", nullable: false), error_message = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true), last_attempt_at = table.Column(type: "timestamp with time zone", nullable: true), next_retry_at = table.Column(type: "timestamp with time zone", nullable: true), sent_at = table.Column(type: "timestamp with time zone", nullable: true), response_status_code = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false), updated_at = table.Column(type: "timestamp with time zone", nullable: false), deleted_at = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("pk_activity_pub_deliveries", x => x.id); }); migrationBuilder.RenameColumn( name: "meta", table: "posts", newName: "metadata"); migrationBuilder.AlterColumn( name: "publisher_id", table: "posts", type: "uuid", nullable: true, oldClrType: typeof(Guid), oldType: "uuid"); migrationBuilder.AddColumn( name: "actor_id", table: "posts", type: "uuid", nullable: true); migrationBuilder.AddColumn( name: "boost_count", table: "posts", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "content_type", table: "posts", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "fediverse_type", table: "posts", type: "integer", nullable: true); migrationBuilder.AddColumn( name: "fediverse_uri", table: "posts", type: "character varying(8192)", maxLength: 8192, nullable: true); migrationBuilder.AddColumn( name: "language", table: "posts", type: "character varying(2048)", maxLength: 2048, nullable: true); migrationBuilder.AddColumn>( name: "mentions", table: "posts", type: "jsonb", nullable: true); migrationBuilder.AddColumn( name: "replies_count", table: "posts", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.AlterColumn( name: "account_id", table: "post_reactions", type: "uuid", nullable: true, oldClrType: typeof(Guid), oldType: "uuid"); migrationBuilder.AddColumn( name: "actor_id", table: "post_reactions", type: "uuid", nullable: true); migrationBuilder.AddColumn( name: "fediverse_uri", table: "post_reactions", type: "character varying(2048)", maxLength: 2048, nullable: true); migrationBuilder.AddColumn( name: "is_local", table: "post_reactions", type: "boolean", nullable: false, defaultValue: false); migrationBuilder.CreateIndex( name: "ix_fediverse_actors_instance_id", table: "fediverse_actors", column: "instance_id"); migrationBuilder.CreateIndex( name: "ix_fediverse_actors_uri", table: "fediverse_actors", column: "uri", unique: true); migrationBuilder.CreateIndex( name: "ix_fediverse_instances_domain", table: "fediverse_instances", column: "domain", unique: true); migrationBuilder.CreateIndex( name: "ix_fediverse_relationships_actor_id", table: "fediverse_relationships", column: "actor_id"); migrationBuilder.CreateIndex( name: "ix_fediverse_relationships_target_actor_id", table: "fediverse_relationships", column: "target_actor_id"); migrationBuilder.CreateIndex( name: "ix_posts_actor_id", table: "posts", column: "actor_id"); migrationBuilder.CreateIndex( name: "ix_post_reactions_actor_id", table: "post_reactions", column: "actor_id"); migrationBuilder.AddForeignKey( name: "fk_post_reactions_fediverse_actors_actor_id", table: "post_reactions", column: "actor_id", principalTable: "fediverse_actors", principalColumn: "id"); migrationBuilder.AddForeignKey( name: "fk_posts_fediverse_actors_actor_id", table: "posts", column: "actor_id", principalTable: "fediverse_actors", principalColumn: "id"); migrationBuilder.AddForeignKey( name: "fk_posts_publishers_publisher_id", table: "posts", column: "publisher_id", principalTable: "publishers", principalColumn: "id", onDelete: ReferentialAction.Cascade); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "fk_post_reactions_fediverse_actors_actor_id", table: "post_reactions"); migrationBuilder.DropForeignKey( name: "fk_posts_fediverse_actors_actor_id", table: "posts"); migrationBuilder.DropForeignKey( name: "fk_posts_publishers_publisher_id", table: "posts"); migrationBuilder.DropIndex( name: "ix_posts_actor_id", table: "posts"); migrationBuilder.DropIndex( name: "ix_post_reactions_actor_id", table: "post_reactions"); migrationBuilder.DropIndex( name: "ix_fediverse_relationships_target_actor_id", table: "fediverse_relationships"); migrationBuilder.DropIndex( name: "ix_fediverse_relationships_actor_id", table: "fediverse_relationships"); migrationBuilder.DropIndex( name: "ix_fediverse_instances_domain", table: "fediverse_instances"); migrationBuilder.DropIndex( name: "ix_fediverse_actors_uri", table: "fediverse_actors"); migrationBuilder.DropIndex( name: "ix_fediverse_actors_instance_id", table: "fediverse_actors"); migrationBuilder.DropColumn( name: "is_local", table: "post_reactions"); migrationBuilder.DropColumn( name: "fediverse_uri", table: "post_reactions"); migrationBuilder.DropColumn( name: "actor_id", table: "post_reactions"); migrationBuilder.AlterColumn( name: "account_id", table: "post_reactions", type: "uuid", nullable: false, defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), oldClrType: typeof(Guid), oldType: "uuid", oldNullable: true); migrationBuilder.DropColumn( name: "replies_count", table: "posts"); migrationBuilder.DropColumn( name: "mentions", table: "posts"); migrationBuilder.DropColumn( name: "language", table: "posts"); migrationBuilder.DropColumn( name: "fediverse_uri", table: "posts"); migrationBuilder.DropColumn( name: "fediverse_type", table: "posts"); migrationBuilder.DropColumn( name: "content_type", table: "posts"); migrationBuilder.DropColumn( name: "boost_count", table: "posts"); migrationBuilder.DropColumn( name: "actor_id", table: "posts"); migrationBuilder.AlterColumn( name: "publisher_id", table: "posts", type: "uuid", nullable: false, defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), oldClrType: typeof(Guid), oldType: "uuid", oldNullable: true); migrationBuilder.RenameColumn( name: "metadata", table: "posts", newName: "meta"); migrationBuilder.DropTable( name: "activity_pub_deliveries"); migrationBuilder.DropTable( name: "fediverse_relationships"); migrationBuilder.DropTable( name: "fediverse_actors"); migrationBuilder.DropTable( name: "fediverse_instances"); migrationBuilder.DropColumn( name: "public_key_pem", table: "publishers"); migrationBuilder.DropColumn( name: "private_key_pem", table: "publishers"); migrationBuilder.DropColumn( name: "meta", table: "publishers"); } } }