fix: add revised migration
All checks were successful
Update changelog / changelog (push) Successful in 25s

This commit is contained in:
2025-12-11 22:37:24 +01:00
parent bade2f9b86
commit 3f225a1ecb
4 changed files with 40 additions and 13 deletions

View File

@@ -4,27 +4,44 @@ import { User } from "./User"
@Entity("links")
export class Link {
// Unique link id.
@PrimaryGeneratedColumn()
id: number
// Experimental: subdomain which should be a part of the short url.
// For instance in the URL "abc.example.com/def", abc is the subdomain.
// "def.example.com/def" won't resolve to the URL that "abc.example.com/def" does.
@Column({ nullable: true })
subdomain: string | null
// Shortened Uri.
@Column()
shortUri: string
// URL to which the user should be redirected
@Column()
fullUrl: string
@Column()
role: string
// Unix timestamp of link creation date.
@Column('bigint')
createDate: number
@Column('bigint')
expiryDate: number
// Unix timestamp of when the link should expire.
// If null, the link will never expire unless deleted.
@Column('bigint', { nullable: true })
expiryDate: number | null
// Aggregated amount of visits.
@Column('bigint')
visits: number
// Link privacy:
// - true, if link is private
// - false, if link can be shown in a list of recent links publicly.
@Column()
privacy: boolean
// User to which the shortened URL belongs.
@ManyToOne(() => User, (user) => user.links, { nullable: true })
@JoinTable()
author: User | null

View File

@@ -4,21 +4,29 @@ import { Link } from "./Link"
@Entity("users")
export class User {
// Unique user id.
@PrimaryGeneratedColumn()
id: number
// User name, must be unique.
@Column({ unique: true })
name: string
// Salted password hash.
@Column()
passwordHash: string
// User role:
// - 0 - means unprivileged user,
// - 1 - means administrative user.
@Column()
role: string
role: number
// Account creation date as a Unix timestamp.
@Column('bigint')
createdAt: number
// List of shortened URLs which belong to the user.
@OneToMany(() => Link, (link) => link.author)
links: Link[];
}

View File

@@ -1,49 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class InitialMigration1764549652720 implements MigrationInterface {
name = 'InitialMigration1764549652720'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE "links" (
"id" SERIAL NOT NULL,
"subdomain" character varying,
"shortUri" character varying NOT NULL,
"fullUrl" character varying NOT NULL,
"role" character varying NOT NULL,
"createDate" bigint NOT NULL,
"expiryDate" bigint NOT NULL,
"authorId" integer,
CONSTRAINT "PK_ecf17f4a741d3c5ba0b4c5ab4b6" PRIMARY KEY ("id")
)
`);
await queryRunner.query(`
CREATE TABLE "users" (
"id" SERIAL NOT NULL,
"name" character varying NOT NULL,
"passwordHash" character varying NOT NULL,
"role" character varying NOT NULL,
"createdAt" bigint NOT NULL,
CONSTRAINT "UQ_51b8b26ac168fbe7d6f5653e6cf" UNIQUE ("name"),
CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id")
)
`);
await queryRunner.query(`
ALTER TABLE "links"
ADD CONSTRAINT "FK_c5287c1e74cbb62159104715543" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "links" DROP CONSTRAINT "FK_c5287c1e74cbb62159104715543"
`);
await queryRunner.query(`
DROP TABLE "users"
`);
await queryRunner.query(`
DROP TABLE "links"
`);
}
}