Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
484 changes: 484 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
40 changes: 40 additions & 0 deletions api/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using api.Models;
using Microsoft.EntityFrameworkCore;

namespace api.Data
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions options)
: base(options)
{
}

public DbSet<User> Users { get; set; }
public DbSet<Tree> Trees { get; set; }
public DbSet<Link> Links { get; set; }
public DbSet<LinktreeAccess> LinktreeAccesses { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<LinktreeAccess>()
.HasKey(la => new { la.TreeId, la.UserId });

modelBuilder.Entity<LinktreeAccess>()
.HasOne(la => la.Tree)
.WithMany(t => t.LinktreeAccesses)
.HasForeignKey(la => la.TreeId);

modelBuilder.Entity<LinktreeAccess>()
.HasOne(la => la.User)
.WithMany(u => u.LinktreeAccesses)
.HasForeignKey(la => la.UserId);
}
}
}
189 changes: 189 additions & 0 deletions api/Migrations/20241023143859_init.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions api/Migrations/20241023143859_init.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace api.Migrations
{
/// <inheritdoc />
public partial class init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
Username = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
RefreshToken = table.Column<string>(type: "text", nullable: true),
Device = table.Column<string>(type: "text", nullable: true),
PhotoProfileUri = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.id);
});

migrationBuilder.CreateTable(
name: "Trees",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Title = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: true),
Slug = table.Column<string>(type: "text", nullable: true),
Visibility = table.Column<int>(type: "integer", nullable: false),
TreeImageUri = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Trees", x => x.Id);
table.ForeignKey(
name: "FK_Trees_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateTable(
name: "Links",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
TreeId = table.Column<Guid>(type: "uuid", nullable: false),
Uri = table.Column<string>(type: "text", nullable: false),
Title = table.Column<string>(type: "text", nullable: false),
ImageUri = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Links", x => x.Id);
table.ForeignKey(
name: "FK_Links_Trees_TreeId",
column: x => x.TreeId,
principalTable: "Trees",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateTable(
name: "LinktreeAccess",
columns: table => new
{
TreeId = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LinktreeAccess", x => new { x.TreeId, x.UserId });
table.ForeignKey(
name: "FK_LinktreeAccess_Trees_TreeId",
column: x => x.TreeId,
principalTable: "Trees",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_LinktreeAccess_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Links_TreeId",
table: "Links",
column: "TreeId");

migrationBuilder.CreateIndex(
name: "IX_LinktreeAccess_UserId",
table: "LinktreeAccess",
column: "UserId");

migrationBuilder.CreateIndex(
name: "IX_Trees_UserId",
table: "Trees",
column: "UserId");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Links");

migrationBuilder.DropTable(
name: "LinktreeAccess");

migrationBuilder.DropTable(
name: "Trees");

migrationBuilder.DropTable(
name: "Users");
}
}
}
Loading