using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace YABA.Data.Migrations { public partial class InitialMigration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "users", columns: table => new { id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), is_deleted = table.Column(type: "boolean", nullable: false), created_on = table.Column(type: "timestamp with time zone", nullable: false), last_modified = table.Column(type: "timestamp with time zone", nullable: false), auth0id = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("pk_users", x => x.id); }); migrationBuilder.CreateTable( name: "bookmarks", columns: table => new { id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), is_deleted = table.Column(type: "boolean", nullable: false), created_on = table.Column(type: "timestamp with time zone", nullable: false), last_modified = table.Column(type: "timestamp with time zone", nullable: false), title = table.Column(type: "text", nullable: false), description = table.Column(type: "text", nullable: false), note = table.Column(type: "text", nullable: false), is_hidden = table.Column(type: "boolean", nullable: false), user_id = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("pk_bookmarks", x => x.id); table.ForeignKey( name: "fk_bookmarks_users_user_id", column: x => x.user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tags", columns: table => new { id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), is_deleted = table.Column(type: "boolean", nullable: false), name = table.Column(type: "text", nullable: false), is_hidden = table.Column(type: "boolean", nullable: false), user_id = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("pk_tags", x => x.id); table.ForeignKey( name: "fk_tags_users_user_id", column: x => x.user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "bookmark_tags", columns: table => new { id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), bookmark_id = table.Column(type: "integer", nullable: false), tag_id = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("pk_bookmark_tags", x => x.id); table.ForeignKey( name: "fk_bookmark_tags_bookmarks_bookmark_id", column: x => x.bookmark_id, principalTable: "bookmarks", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_bookmark_tags_tags_tag_id", column: x => x.tag_id, principalTable: "tags", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "ix_bookmark_tags_bookmark_id_tag_id", table: "bookmark_tags", columns: new[] { "bookmark_id", "tag_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_bookmark_tags_tag_id", table: "bookmark_tags", column: "tag_id"); migrationBuilder.CreateIndex( name: "ix_bookmarks_user_id", table: "bookmarks", column: "user_id"); migrationBuilder.CreateIndex( name: "ix_tags_user_id", table: "tags", column: "user_id"); migrationBuilder.CreateIndex( name: "ix_users_auth0id", table: "users", column: "auth0id", unique: true); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "bookmark_tags"); migrationBuilder.DropTable( name: "bookmarks"); migrationBuilder.DropTable( name: "tags"); migrationBuilder.DropTable( name: "users"); } } }