From 3f225a1ecb1e19edb593e8e4ac6923c624455d18 Mon Sep 17 00:00:00 2001 From: sherl Date: Thu, 11 Dec 2025 22:37:24 +0100 Subject: [PATCH] fix: add revised migration --- .gitea/workflows/02_release.yaml | 5 ++-- .../1765488793696-revisedMigration.ts | 11 ++++---- src/entities/Link.ts | 27 +++++++++++++++---- src/entities/User.ts | 10 ++++++- 4 files changed, 40 insertions(+), 13 deletions(-) rename src/migrations/1764549652720-initialMigration.ts => migrations/1765488793696-revisedMigration.ts (85%) diff --git a/.gitea/workflows/02_release.yaml b/.gitea/workflows/02_release.yaml index 76503f3..eb1466f 100644 --- a/.gitea/workflows/02_release.yaml +++ b/.gitea/workflows/02_release.yaml @@ -12,10 +12,11 @@ jobs: runs-on: ubuntu-latest container: docker.io/thegeeklab/git-sv:2.0.9 steps: - - name: install tools + - name: Install tools run: | apk add -q --update --no-cache nodejs - - uses: actions/checkout@v6 + - name: Checkout repository + uses: actions/checkout@v6 with: fetch-tags: true fetch-depth: 0 diff --git a/src/migrations/1764549652720-initialMigration.ts b/migrations/1765488793696-revisedMigration.ts similarity index 85% rename from src/migrations/1764549652720-initialMigration.ts rename to migrations/1765488793696-revisedMigration.ts index ad3c931..f3a48ad 100644 --- a/src/migrations/1764549652720-initialMigration.ts +++ b/migrations/1765488793696-revisedMigration.ts @@ -1,7 +1,7 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class InitialMigration1764549652720 implements MigrationInterface { - name = 'InitialMigration1764549652720' +export class RevisedMigration1765488793696 implements MigrationInterface { + name = 'RevisedMigration1765488793696' public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(` @@ -10,9 +10,10 @@ export class InitialMigration1764549652720 implements MigrationInterface { "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, + "expiryDate" bigint, + "visits" bigint NOT NULL, + "privacy" boolean NOT NULL, "authorId" integer, CONSTRAINT "PK_ecf17f4a741d3c5ba0b4c5ab4b6" PRIMARY KEY ("id") ) @@ -22,7 +23,7 @@ export class InitialMigration1764549652720 implements MigrationInterface { "id" SERIAL NOT NULL, "name" character varying NOT NULL, "passwordHash" character varying NOT NULL, - "role" character varying NOT NULL, + "role" integer NOT NULL, "createdAt" bigint NOT NULL, CONSTRAINT "UQ_51b8b26ac168fbe7d6f5653e6cf" UNIQUE ("name"), CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id") diff --git a/src/entities/Link.ts b/src/entities/Link.ts index fe06e04..da24bd1 100644 --- a/src/entities/Link.ts +++ b/src/entities/Link.ts @@ -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 diff --git a/src/entities/User.ts b/src/entities/User.ts index 212e367..cbacd28 100644 --- a/src/entities/User.ts +++ b/src/entities/User.ts @@ -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[]; }