chore: add csharpier to husky, format backend with csharpier

This commit is contained in:
sam 2024-10-02 00:28:07 +02:00
parent 5fab66444f
commit 7f971e8549
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
73 changed files with 2098 additions and 1048 deletions

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
#nullable disable
@ -22,12 +22,13 @@ namespace Foxnouns.Backend.Database.Migrations
domain = table.Column<string>(type: "text", nullable: false),
client_id = table.Column<string>(type: "text", nullable: false),
client_secret = table.Column<string>(type: "text", nullable: false),
instance_type = table.Column<int>(type: "integer", nullable: false)
instance_type = table.Column<int>(type: "integer", nullable: false),
},
constraints: table =>
{
table.PrimaryKey("pk_fediverse_applications", x => x.id);
});
}
);
migrationBuilder.CreateTable(
name: "users",
@ -43,12 +44,13 @@ namespace Foxnouns.Backend.Database.Migrations
role = table.Column<int>(type: "integer", nullable: false),
fields = table.Column<string>(type: "jsonb", nullable: false),
names = table.Column<string>(type: "jsonb", nullable: false),
pronouns = table.Column<string>(type: "jsonb", nullable: false)
pronouns = table.Column<string>(type: "jsonb", nullable: false),
},
constraints: table =>
{
table.PrimaryKey("pk_users", x => x.id);
});
}
);
migrationBuilder.CreateTable(
name: "auth_methods",
@ -59,7 +61,7 @@ namespace Foxnouns.Backend.Database.Migrations
remote_id = table.Column<string>(type: "text", nullable: false),
remote_username = table.Column<string>(type: "text", nullable: true),
user_id = table.Column<long>(type: "bigint", nullable: false),
fediverse_application_id = table.Column<long>(type: "bigint", nullable: true)
fediverse_application_id = table.Column<long>(type: "bigint", nullable: true),
},
constraints: table =>
{
@ -68,14 +70,17 @@ namespace Foxnouns.Backend.Database.Migrations
name: "fk_auth_methods_fediverse_applications_fediverse_application_id",
column: x => x.fediverse_application_id,
principalTable: "fediverse_applications",
principalColumn: "id");
principalColumn: "id"
);
table.ForeignKey(
name: "fk_auth_methods_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
onDelete: ReferentialAction.Cascade
);
}
);
migrationBuilder.CreateTable(
name: "members",
@ -91,7 +96,7 @@ namespace Foxnouns.Backend.Database.Migrations
user_id = table.Column<long>(type: "bigint", nullable: false),
fields = table.Column<string>(type: "jsonb", nullable: false),
names = table.Column<string>(type: "jsonb", nullable: false),
pronouns = table.Column<string>(type: "jsonb", nullable: false)
pronouns = table.Column<string>(type: "jsonb", nullable: false),
},
constraints: table =>
{
@ -101,18 +106,23 @@ namespace Foxnouns.Backend.Database.Migrations
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
onDelete: ReferentialAction.Cascade
);
}
);
migrationBuilder.CreateTable(
name: "tokens",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false),
expires_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
expires_at = table.Column<Instant>(
type: "timestamp with time zone",
nullable: false
),
scopes = table.Column<string[]>(type: "text[]", nullable: false),
manually_expired = table.Column<bool>(type: "boolean", nullable: false),
user_id = table.Column<long>(type: "bigint", nullable: false)
user_id = table.Column<long>(type: "bigint", nullable: false),
},
constraints: table =>
{
@ -122,53 +132,56 @@ namespace Foxnouns.Backend.Database.Migrations
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
onDelete: ReferentialAction.Cascade
);
}
);
migrationBuilder.CreateIndex(
name: "ix_auth_methods_fediverse_application_id",
table: "auth_methods",
column: "fediverse_application_id");
column: "fediverse_application_id"
);
migrationBuilder.CreateIndex(
name: "ix_auth_methods_user_id",
table: "auth_methods",
column: "user_id");
column: "user_id"
);
// EF Core doesn't support creating indexes on arbitrary expressions, so we have to create it manually.
// Due to historical reasons (I made a mistake while writing the initial migration for the Go version)
// only members have case-insensitive names.
migrationBuilder.Sql("CREATE UNIQUE INDEX ix_members_user_id_name ON members (user_id, lower(name))");
migrationBuilder.Sql(
"CREATE UNIQUE INDEX ix_members_user_id_name ON members (user_id, lower(name))"
);
migrationBuilder.CreateIndex(
name: "ix_tokens_user_id",
table: "tokens",
column: "user_id");
column: "user_id"
);
migrationBuilder.CreateIndex(
name: "ix_users_username",
table: "users",
column: "username",
unique: true);
unique: true
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "auth_methods");
migrationBuilder.DropTable(name: "auth_methods");
migrationBuilder.DropTable(
name: "members");
migrationBuilder.DropTable(name: "members");
migrationBuilder.DropTable(
name: "tokens");
migrationBuilder.DropTable(name: "tokens");
migrationBuilder.DropTable(
name: "fediverse_applications");
migrationBuilder.DropTable(name: "fediverse_applications");
migrationBuilder.DropTable(
name: "users");
migrationBuilder.DropTable(name: "users");
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@ -18,14 +18,16 @@ namespace Foxnouns.Backend.Database.Migrations
table: "tokens",
type: "bigint",
nullable: false,
defaultValue: 0L);
defaultValue: 0L
);
migrationBuilder.AddColumn<byte[]>(
name: "hash",
table: "tokens",
type: "bytea",
nullable: false,
defaultValue: new byte[0]);
defaultValue: new byte[0]
);
migrationBuilder.CreateTable(
name: "applications",
@ -36,17 +38,19 @@ namespace Foxnouns.Backend.Database.Migrations
client_secret = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: false),
scopes = table.Column<string[]>(type: "text[]", nullable: false),
redirect_uris = table.Column<string[]>(type: "text[]", nullable: false)
redirect_uris = table.Column<string[]>(type: "text[]", nullable: false),
},
constraints: table =>
{
table.PrimaryKey("pk_applications", x => x.id);
});
}
);
migrationBuilder.CreateIndex(
name: "ix_tokens_application_id",
table: "tokens",
column: "application_id");
column: "application_id"
);
migrationBuilder.AddForeignKey(
name: "fk_tokens_applications_application_id",
@ -54,7 +58,8 @@ namespace Foxnouns.Backend.Database.Migrations
column: "application_id",
principalTable: "applications",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Cascade
);
}
/// <inheritdoc />
@ -62,22 +67,16 @@ namespace Foxnouns.Backend.Database.Migrations
{
migrationBuilder.DropForeignKey(
name: "fk_tokens_applications_application_id",
table: "tokens");
table: "tokens"
);
migrationBuilder.DropTable(
name: "applications");
migrationBuilder.DropTable(name: "applications");
migrationBuilder.DropIndex(
name: "ix_tokens_application_id",
table: "tokens");
migrationBuilder.DropIndex(name: "ix_tokens_application_id", table: "tokens");
migrationBuilder.DropColumn(
name: "application_id",
table: "tokens");
migrationBuilder.DropColumn(name: "application_id", table: "tokens");
migrationBuilder.DropColumn(
name: "hash",
table: "tokens");
migrationBuilder.DropColumn(name: "hash", table: "tokens");
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@ -18,15 +18,14 @@ namespace Foxnouns.Backend.Database.Migrations
table: "users",
type: "boolean",
nullable: false,
defaultValue: false);
defaultValue: false
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "list_hidden",
table: "users");
migrationBuilder.DropColumn(name: "list_hidden", table: "users");
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@ -17,15 +17,14 @@ namespace Foxnouns.Backend.Database.Migrations
name: "password",
table: "users",
type: "text",
nullable: true);
nullable: true
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "password",
table: "users");
migrationBuilder.DropColumn(name: "password", table: "users");
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
@ -19,29 +19,37 @@ namespace Foxnouns.Backend.Database.Migrations
name: "temporary_keys",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id = table
.Column<long>(type: "bigint", nullable: false)
.Annotation(
"Npgsql:ValueGenerationStrategy",
NpgsqlValueGenerationStrategy.IdentityByDefaultColumn
),
key = table.Column<string>(type: "text", nullable: false),
value = table.Column<string>(type: "text", nullable: false),
expires = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
expires = table.Column<Instant>(
type: "timestamp with time zone",
nullable: false
),
},
constraints: table =>
{
table.PrimaryKey("pk_temporary_keys", x => x.id);
});
}
);
migrationBuilder.CreateIndex(
name: "ix_temporary_keys_key",
table: "temporary_keys",
column: "key",
unique: true);
unique: true
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "temporary_keys");
migrationBuilder.DropTable(name: "temporary_keys");
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
#nullable disable
@ -19,15 +19,14 @@ namespace Foxnouns.Backend.Database.Migrations
table: "users",
type: "timestamp with time zone",
nullable: false,
defaultValueSql: "now()");
defaultValueSql: "now()"
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "last_active",
table: "users");
migrationBuilder.DropColumn(name: "last_active", table: "users");
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
#nullable disable
@ -19,35 +19,32 @@ namespace Foxnouns.Backend.Database.Migrations
table: "users",
type: "boolean",
nullable: false,
defaultValue: false);
defaultValue: false
);
migrationBuilder.AddColumn<Instant>(
name: "deleted_at",
table: "users",
type: "timestamp with time zone",
nullable: true);
nullable: true
);
migrationBuilder.AddColumn<long>(
name: "deleted_by",
table: "users",
type: "bigint",
nullable: true);
nullable: true
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "deleted",
table: "users");
migrationBuilder.DropColumn(name: "deleted", table: "users");
migrationBuilder.DropColumn(
name: "deleted_at",
table: "users");
migrationBuilder.DropColumn(name: "deleted_at", table: "users");
migrationBuilder.DropColumn(
name: "deleted_by",
table: "users");
migrationBuilder.DropColumn(name: "deleted_by", table: "users");
}
}
}

View file

@ -1,7 +1,7 @@
using System;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System.Collections.Generic;
using Foxnouns.Backend.Database.Models;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@ -21,15 +21,14 @@ namespace Foxnouns.Backend.Database.Migrations
table: "users",
type: "jsonb",
nullable: false,
defaultValueSql: "'{}'");
defaultValueSql: "'{}'"
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "custom_preferences",
table: "users");
migrationBuilder.DropColumn(name: "custom_preferences", table: "users");
}
}
}

View file

@ -19,15 +19,14 @@ namespace Foxnouns.Backend.Database.Migrations
table: "users",
type: "jsonb",
nullable: false,
defaultValueSql: "'{}'");
defaultValueSql: "'{}'"
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "settings",
table: "users");
migrationBuilder.DropColumn(name: "settings", table: "users");
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
#nullable disable
@ -18,38 +18,46 @@ namespace Foxnouns.Backend.Database.Migrations
name: "sid",
table: "users",
type: "text",
nullable: true);
nullable: true
);
migrationBuilder.AddColumn<Instant>(
name: "last_sid_reroll",
table: "users",
type: "timestamp with time zone",
nullable: false,
defaultValueSql: "now() - '1 hour'::interval");
defaultValueSql: "now() - '1 hour'::interval"
);
migrationBuilder.AddColumn<string>(
name: "sid",
table: "members",
type: "text",
nullable: true);
nullable: true
);
migrationBuilder.CreateIndex(
name: "ix_users_sid",
table: "users",
column: "sid",
unique: true);
unique: true
);
migrationBuilder.CreateIndex(
name: "ix_members_sid",
table: "members",
column: "sid",
unique: true);
unique: true
);
migrationBuilder.Sql(@"create function generate_sid(len int) returns text as $$
migrationBuilder.Sql(
@"create function generate_sid(len int) returns text as $$
select string_agg(substr('abcdefghijklmnopqrstuvwxyz', ceil(random() * 26)::integer, 1), '') from generate_series(1, len)
$$ language sql volatile;
");
migrationBuilder.Sql(@"create function find_free_user_sid() returns text as $$
"
);
migrationBuilder.Sql(
@"create function find_free_user_sid() returns text as $$
declare new_sid text;
begin
loop
@ -58,8 +66,10 @@ begin
end loop;
end
$$ language plpgsql volatile;
");
migrationBuilder.Sql(@"create function find_free_member_sid() returns text as $$
"
);
migrationBuilder.Sql(
@"create function find_free_member_sid() returns text as $$
declare new_sid text;
begin
loop
@ -67,7 +77,8 @@ begin
if not exists (select 1 from members where sid = new_sid) then return new_sid; end if;
end loop;
end
$$ language plpgsql volatile;");
$$ language plpgsql volatile;"
);
}
/// <inheritdoc />
@ -77,25 +88,15 @@ $$ language plpgsql volatile;");
migrationBuilder.Sql("drop function find_free_user_sid;");
migrationBuilder.Sql("drop function generate_sid;");
migrationBuilder.DropIndex(
name: "ix_users_sid",
table: "users");
migrationBuilder.DropIndex(name: "ix_users_sid", table: "users");
migrationBuilder.DropIndex(
name: "ix_members_sid",
table: "members");
migrationBuilder.DropIndex(name: "ix_members_sid", table: "members");
migrationBuilder.DropColumn(
name: "sid",
table: "users");
migrationBuilder.DropColumn(name: "sid", table: "users");
migrationBuilder.DropColumn(
name: "last_sid_reroll",
table: "users");
migrationBuilder.DropColumn(name: "last_sid_reroll", table: "users");
migrationBuilder.DropColumn(
name: "sid",
table: "members");
migrationBuilder.DropColumn(name: "sid", table: "members");
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
#nullable disable
@ -22,7 +22,8 @@ namespace Foxnouns.Backend.Database.Migrations
defaultValueSql: "find_free_user_sid()",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
oldNullable: true
);
migrationBuilder.AlterColumn<string>(
name: "sid",
@ -32,7 +33,8 @@ namespace Foxnouns.Backend.Database.Migrations
defaultValueSql: "find_free_member_sid()",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
oldNullable: true
);
}
/// <inheritdoc />
@ -45,7 +47,8 @@ namespace Foxnouns.Backend.Database.Migrations
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldDefaultValueSql: "find_free_user_sid()");
oldDefaultValueSql: "find_free_user_sid()"
);
migrationBuilder.AlterColumn<string>(
name: "sid",
@ -54,7 +57,8 @@ namespace Foxnouns.Backend.Database.Migrations
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldDefaultValueSql: "find_free_member_sid()");
oldDefaultValueSql: "find_free_member_sid()"
);
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
@ -22,7 +22,7 @@ namespace Foxnouns.Backend.Database.Migrations
user_id = table.Column<long>(type: "bigint", nullable: false),
hash = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: false),
description = table.Column<string>(type: "text", nullable: true)
description = table.Column<string>(type: "text", nullable: true),
},
constraints: table =>
{
@ -32,17 +32,23 @@ namespace Foxnouns.Backend.Database.Migrations
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
onDelete: ReferentialAction.Cascade
);
}
);
migrationBuilder.CreateTable(
name: "member_flags",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id = table
.Column<long>(type: "bigint", nullable: false)
.Annotation(
"Npgsql:ValueGenerationStrategy",
NpgsqlValueGenerationStrategy.IdentityByDefaultColumn
),
member_id = table.Column<long>(type: "bigint", nullable: false),
pride_flag_id = table.Column<long>(type: "bigint", nullable: false)
pride_flag_id = table.Column<long>(type: "bigint", nullable: false),
},
constraints: table =>
{
@ -52,23 +58,30 @@ namespace Foxnouns.Backend.Database.Migrations
column: x => x.member_id,
principalTable: "members",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Cascade
);
table.ForeignKey(
name: "fk_member_flags_pride_flags_pride_flag_id",
column: x => x.pride_flag_id,
principalTable: "pride_flags",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
onDelete: ReferentialAction.Cascade
);
}
);
migrationBuilder.CreateTable(
name: "user_flags",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id = table
.Column<long>(type: "bigint", nullable: false)
.Annotation(
"Npgsql:ValueGenerationStrategy",
NpgsqlValueGenerationStrategy.IdentityByDefaultColumn
),
user_id = table.Column<long>(type: "bigint", nullable: false),
pride_flag_id = table.Column<long>(type: "bigint", nullable: false)
pride_flag_id = table.Column<long>(type: "bigint", nullable: false),
},
constraints: table =>
{
@ -78,52 +91,57 @@ namespace Foxnouns.Backend.Database.Migrations
column: x => x.pride_flag_id,
principalTable: "pride_flags",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Cascade
);
table.ForeignKey(
name: "fk_user_flags_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
onDelete: ReferentialAction.Cascade
);
}
);
migrationBuilder.CreateIndex(
name: "ix_member_flags_member_id",
table: "member_flags",
column: "member_id");
column: "member_id"
);
migrationBuilder.CreateIndex(
name: "ix_member_flags_pride_flag_id",
table: "member_flags",
column: "pride_flag_id");
column: "pride_flag_id"
);
migrationBuilder.CreateIndex(
name: "ix_pride_flags_user_id",
table: "pride_flags",
column: "user_id");
column: "user_id"
);
migrationBuilder.CreateIndex(
name: "ix_user_flags_pride_flag_id",
table: "user_flags",
column: "pride_flag_id");
column: "pride_flag_id"
);
migrationBuilder.CreateIndex(
name: "ix_user_flags_user_id",
table: "user_flags",
column: "user_id");
column: "user_id"
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "member_flags");
migrationBuilder.DropTable(name: "member_flags");
migrationBuilder.DropTable(
name: "user_flags");
migrationBuilder.DropTable(name: "user_flags");
migrationBuilder.DropTable(
name: "pride_flags");
migrationBuilder.DropTable(name: "pride_flags");
}
}
}