~jan0sch/smederee

Showing details for patch fd4fd6b262b4928d51952d36bdbe37ab63fb1d25.
2022-08-11 (Thu), 2:24 PM - Jens Grassel - fd4fd6b262b4928d51952d36bdbe37ab63fb1d25

VCS: Prepare repository db tables

Summary of changes
1 files added
  • modules/hub/src/main/resources/db/migration/V2__repository_tables.sql
1 files modified with 42 lines added and 2 lines removed
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepository.scala with 42 added and 2 removed lines
diff -rN -u old-smederee/modules/hub/src/main/resources/db/migration/V2__repository_tables.sql new-smederee/modules/hub/src/main/resources/db/migration/V2__repository_tables.sql
--- old-smederee/modules/hub/src/main/resources/db/migration/V2__repository_tables.sql	1970-01-01 00:00:00.000000000 +0000
+++ new-smederee/modules/hub/src/main/resources/db/migration/V2__repository_tables.sql	2025-02-02 16:57:19.811137920 +0000
@@ -0,0 +1,28 @@
+CREATE TABLE "repositories"
+(
+  "id"          BIGINT                   GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
+  "name"        CHARACTER VARYING(64)    NOT NULL,
+  "owner"       UUID                     NOT NULL,
+  "is_private"  BOOLEAN                  DEFAULT FALSE,
+  "description" CHARACTER VARYING(254),
+  "website"     TEXT,
+  "created_at"  TIMESTAMP WITH TIME ZONE NOT NULL,
+  "updated_at"  TIMESTAMP WITH TIME ZONE NOT NULL,
+  CONSTRAINT "repositories_unique_owner_name" UNIQUE ("owner", "name"),
+  CONSTRAINT "repositories_fk_uid" FOREIGN KEY ("owner")
+    REFERENCES "accounts" ("uid") ON UPDATE CASCADE ON DELETE CASCADE
+)
+WITH (
+  OIDS=FALSE
+);
+
+COMMENT ON TABLE "repositories" IS 'All repositories i.e. their metadata are stored within this table. The combination of owner id and repository name must always be unique.';
+COMMENT ON COLUMN "repositories"."id" IS 'An auto generated primary key.';
+COMMENT ON COLUMN "repositories"."name" IS 'A repository name must start with a letter or number and must contain only alphanumeric ASCII characters as well as minus or underscore signs. It must be between 2 and 64 characters long.';
+COMMENT ON COLUMN "repositories"."owner" IS 'The unique ID of the user account that owns the repository.';
+COMMENT ON COLUMN "repositories"."is_private" IS 'A flag indicating if this repository is private i.e. only visible / accessible for accounts with appropriate permissions.';
+COMMENT ON COLUMN "repositories"."description" IS 'An optional short text description of the repository.';
+COMMENT ON COLUMN "repositories"."website" IS 'An optional uri pointing to a website related to the repository / project.';
+COMMENT ON COLUMN "repositories"."created_at" IS 'The timestamp of when the repository was created.';
+COMMENT ON COLUMN "repositories"."updated_at" IS 'A timestamp when the repository was last changed.';
+
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepository.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepository.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepository.scala	2025-02-02 16:57:19.811137920 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepository.scala	2025-02-02 16:57:19.811137920 +0000
@@ -11,9 +11,34 @@
 
 import cats.data._
 import cats.syntax.all._
+import org.http4s.Uri
 
 import scala.util.matching.Regex
 
+opaque type VcsRepositoryDescription = String
+object VcsRepositoryDescription {
+  val MaximumLength: Int = 254
+
+  /** Create an instance of VcsRepositoryDescription from the given String type.
+    *
+    * @param source
+    *   An instance of type String which will be returned as a VcsRepositoryDescription.
+    * @return
+    *   The appropriate instance of VcsRepositoryDescription.
+    */
+  def apply(source: String): VcsRepositoryDescription = source
+
+  /** Try to create an instance of VcsRepositoryDescription from the given String.
+    *
+    * @param source
+    *   A String that should fulfil the requirements to be converted into a VcsRepositoryDescription.
+    * @return
+    *   An option to the successfully converted VcsRepositoryDescription.
+    */
+  def from(source: String): Option[VcsRepositoryDescription] = Option(source).map(_.take(MaximumLength))
+
+}
+
 opaque type VcsRepositoryName = String
 object VcsRepositoryName {
 
@@ -79,8 +104,23 @@
 /** Data about a VCS respository.
   *
   * @param name
-  *   The name of the repository.
+  *   The name of the repository. A repository name must start with a letter or number and must contain only
+  *   alphanumeric ASCII characters as well as minus or underscore signs. It must be between 2 and 64
+  *   characters long.
   * @param owner
   *   The account that owns the repository.
+  * @param isPrivate
+  *   A flag indicating if this repository is private i.e. only visible / accessible for accounts with
+  *   appropriate permissions.
+  * @param description
+  *   An optional short text description of the repository.
+  * @param website
+  *   An optional uri pointing to a website related to the repository / project.
   */
-final case class VcsRepository(name: VcsRepositoryName, owner: Account)
+final case class VcsRepository(
+    name: VcsRepositoryName,
+    owner: Account,
+    isPrivate: Boolean,
+    description: Option[VcsRepositoryDescription],
+    website: Option[Uri]
+)