using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Cleanuparr.Persistence.Postgres.Migrations.Users { /// public partial class InitialPostgres : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.EnsureSchema( name: "users"); migrationBuilder.CreateTable( name: "users", schema: "users", columns: table => new { id = table.Column(type: "uuid", nullable: false), username = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), password_hash = table.Column(type: "text", nullable: false), totp_secret = table.Column(type: "text", nullable: false), totp_enabled = table.Column(type: "boolean", nullable: false), plex_account_id = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), plex_username = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), plex_email = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), plex_auth_token = table.Column(type: "text", nullable: true), api_key = table.Column(type: "text", nullable: false), setup_completed = table.Column(type: "boolean", nullable: false), failed_login_attempts = table.Column(type: "integer", nullable: false), lockout_end = 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), oidc_authorized_subject = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), oidc_client_id = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), oidc_client_secret = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), oidc_enabled = table.Column(type: "boolean", nullable: false), oidc_exclusive_mode = table.Column(type: "boolean", nullable: false), oidc_issuer_url = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), oidc_provider_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), oidc_redirect_url = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), oidc_scopes = table.Column(type: "character varying(500)", maxLength: 500, nullable: false) }, constraints: table => { table.PrimaryKey("pk_users", x => x.id); }); migrationBuilder.CreateTable( name: "recovery_codes", schema: "users", columns: table => new { id = table.Column(type: "uuid", nullable: false), user_id = table.Column(type: "uuid", nullable: false), code_hash = table.Column(type: "text", nullable: false), is_used = table.Column(type: "boolean", nullable: false), used_at = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("pk_recovery_codes", x => x.id); table.ForeignKey( name: "fk_recovery_codes_users_user_id", column: x => x.user_id, principalSchema: "users", principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "refresh_tokens", schema: "users", columns: table => new { id = table.Column(type: "uuid", nullable: false), user_id = table.Column(type: "uuid", nullable: false), token_hash = table.Column(type: "text", nullable: false), expires_at = table.Column(type: "timestamp with time zone", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false), revoked_at = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("pk_refresh_tokens", x => x.id); table.ForeignKey( name: "fk_refresh_tokens_users_user_id", column: x => x.user_id, principalSchema: "users", principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_feature_views", schema: "users", columns: table => new { id = table.Column(type: "uuid", nullable: false), user_id = table.Column(type: "uuid", nullable: false), feature_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), first_seen_at = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("pk_user_feature_views", x => x.id); table.ForeignKey( name: "fk_user_feature_views_users_user_id", column: x => x.user_id, principalSchema: "users", principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "ix_recovery_codes_user_id", schema: "users", table: "recovery_codes", column: "user_id"); migrationBuilder.CreateIndex( name: "ix_refresh_tokens_token_hash", schema: "users", table: "refresh_tokens", column: "token_hash", unique: true); migrationBuilder.CreateIndex( name: "ix_refresh_tokens_user_id", schema: "users", table: "refresh_tokens", column: "user_id"); migrationBuilder.CreateIndex( name: "ix_user_feature_views_user_id_feature_id", schema: "users", table: "user_feature_views", columns: new[] { "user_id", "feature_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_users_api_key", schema: "users", table: "users", column: "api_key", unique: true); migrationBuilder.CreateIndex( name: "ix_users_username", schema: "users", table: "users", column: "username", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "recovery_codes", schema: "users"); migrationBuilder.DropTable( name: "refresh_tokens", schema: "users"); migrationBuilder.DropTable( name: "user_feature_views", schema: "users"); migrationBuilder.DropTable( name: "users", schema: "users"); } } }