1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 09:02:48 -05:00

Initial db work (#1687)

* Add organization sponsorship databases to all providers

* Generalize create and update for database, specialize in code
This commit is contained in:
Matt Gibson
2021-11-04 10:46:49 -05:00
committed by GitHub
parent ee46a6d63b
commit 079adc60b6
26 changed files with 4276 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Bit.PostgresMigrations.Migrations
{
public partial class OrganizationSponsorship : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "UsesCryptoAgent",
table: "User",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.CreateTable(
name: "OrganizationSponsorship",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
InstallationId = table.Column<Guid>(type: "uuid", nullable: true),
SponsoringOrganizationId = table.Column<Guid>(type: "uuid", nullable: false),
SponsoringOrganizationUserId = table.Column<Guid>(type: "uuid", nullable: false),
SponsoredOrganizationId = table.Column<Guid>(type: "uuid", nullable: true),
OfferedToEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
CloudSponsor = table.Column<bool>(type: "boolean", nullable: false),
LastSyncDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
TimesRenewedWithoutValidation = table.Column<byte>(type: "smallint", nullable: false),
SponsorshipLapsedDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_OrganizationSponsorship", x => x.Id);
table.ForeignKey(
name: "FK_OrganizationSponsorship_Installation_InstallationId",
column: x => x.InstallationId,
principalTable: "Installation",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_OrganizationSponsorship_Organization_SponsoredOrganizationId",
column: x => x.SponsoredOrganizationId,
principalTable: "Organization",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_OrganizationSponsorship_Organization_SponsoringOrganization~",
column: x => x.SponsoringOrganizationId,
principalTable: "Organization",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_OrganizationSponsorship_InstallationId",
table: "OrganizationSponsorship",
column: "InstallationId");
migrationBuilder.CreateIndex(
name: "IX_OrganizationSponsorship_SponsoredOrganizationId",
table: "OrganizationSponsorship",
column: "SponsoredOrganizationId");
migrationBuilder.CreateIndex(
name: "IX_OrganizationSponsorship_SponsoringOrganizationId",
table: "OrganizationSponsorship",
column: "SponsoringOrganizationId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OrganizationSponsorship");
migrationBuilder.DropColumn(
name: "UsesCryptoAgent",
table: "User");
}
}
}

View File

@ -589,6 +589,50 @@ namespace Bit.PostgresMigrations.Migrations
b.ToTable("Organization");
});
modelBuilder.Entity("Bit.Core.Models.EntityFramework.OrganizationSponsorship", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid");
b.Property<bool>("CloudSponsor")
.HasColumnType("boolean");
b.Property<Guid?>("InstallationId")
.HasColumnType("uuid");
b.Property<DateTime?>("LastSyncDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("OfferedToEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<Guid?>("SponsoredOrganizationId")
.HasColumnType("uuid");
b.Property<Guid>("SponsoringOrganizationId")
.HasColumnType("uuid");
b.Property<Guid>("SponsoringOrganizationUserId")
.HasColumnType("uuid");
b.Property<DateTime?>("SponsorshipLapsedDate")
.HasColumnType("timestamp without time zone");
b.Property<byte>("TimesRenewedWithoutValidation")
.HasColumnType("smallint");
b.HasKey("Id");
b.HasIndex("InstallationId");
b.HasIndex("SponsoredOrganizationId");
b.HasIndex("SponsoringOrganizationId");
b.ToTable("OrganizationSponsorship");
});
modelBuilder.Entity("Bit.Core.Models.EntityFramework.OrganizationUser", b =>
{
b.Property<Guid>("Id")
@ -1136,6 +1180,9 @@ namespace Bit.PostgresMigrations.Migrations
.HasMaxLength(32)
.HasColumnType("character varying(32)");
b.Property<bool>("UsesCryptoAgent")
.HasColumnType("boolean");
b.HasKey("Id");
b.ToTable("User");
@ -1301,6 +1348,29 @@ namespace Bit.PostgresMigrations.Migrations
b.Navigation("OrganizationUser");
});
modelBuilder.Entity("Bit.Core.Models.EntityFramework.OrganizationSponsorship", b =>
{
b.HasOne("Bit.Core.Models.EntityFramework.Installation", "Installation")
.WithMany()
.HasForeignKey("InstallationId");
b.HasOne("Bit.Core.Models.EntityFramework.Organization", "SponsoredOrganization")
.WithMany()
.HasForeignKey("SponsoredOrganizationId");
b.HasOne("Bit.Core.Models.EntityFramework.Organization", "SponsoringOrganization")
.WithMany()
.HasForeignKey("SponsoringOrganizationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Installation");
b.Navigation("SponsoredOrganization");
b.Navigation("SponsoringOrganization");
});
modelBuilder.Entity("Bit.Core.Models.EntityFramework.OrganizationUser", b =>
{
b.HasOne("Bit.Core.Models.EntityFramework.Organization", "Organization")

View File

@ -0,0 +1,31 @@
START TRANSACTION;
ALTER TABLE "User" ADD "UsesCryptoAgent" boolean NOT NULL DEFAULT FALSE;
CREATE TABLE "OrganizationSponsorship" (
"Id" uuid NOT NULL,
"InstallationId" uuid NULL,
"SponsoringOrganizationId" uuid NOT NULL,
"SponsoringOrganizationUserId" uuid NOT NULL,
"SponsoredOrganizationId" uuid NULL,
"OfferedToEmail" character varying(256) NULL,
"CloudSponsor" boolean NOT NULL,
"LastSyncDate" timestamp without time zone NULL,
"TimesRenewedWithoutValidation" smallint NOT NULL,
"SponsorshipLapsedDate" timestamp without time zone NULL,
CONSTRAINT "PK_OrganizationSponsorship" PRIMARY KEY ("Id"),
CONSTRAINT "FK_OrganizationSponsorship_Installation_InstallationId" FOREIGN KEY ("InstallationId") REFERENCES "Installation" ("Id") ON DELETE RESTRICT,
CONSTRAINT "FK_OrganizationSponsorship_Organization_SponsoredOrganizationId" FOREIGN KEY ("SponsoredOrganizationId") REFERENCES "Organization" ("Id") ON DELETE RESTRICT,
CONSTRAINT "FK_OrganizationSponsorship_Organization_SponsoringOrganization~" FOREIGN KEY ("SponsoringOrganizationId") REFERENCES "Organization" ("Id") ON DELETE CASCADE
);
CREATE INDEX "IX_OrganizationSponsorship_InstallationId" ON "OrganizationSponsorship" ("InstallationId");
CREATE INDEX "IX_OrganizationSponsorship_SponsoredOrganizationId" ON "OrganizationSponsorship" ("SponsoredOrganizationId");
CREATE INDEX "IX_OrganizationSponsorship_SponsoringOrganizationId" ON "OrganizationSponsorship" ("SponsoringOrganizationId");
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20211102205745_OrganizationSponsorship', '5.0.9');
COMMIT;