mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 18:38:26 +00:00
Add a use colum to metadata entities
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
ALTER TABLE "equipment"
|
||||
ADD COLUMN "equip_use" varchar(254);
|
||||
|
||||
UPDATE "equipment" SET "equip_use" = 'concerning';
|
||||
|
||||
ALTER TABLE "equipment"
|
||||
ALTER COLUMN "equip_use" SET NOT NULL;
|
||||
|
||||
|
||||
ALTER TABLE "organization"
|
||||
ADD COLUMN "org_use" varchar(254);
|
||||
|
||||
UPDATE "organization" SET "org_use" = 'correspondent';
|
||||
|
||||
ALTER TABLE "organization"
|
||||
ALTER COLUMN "org_use" SET NOT NULL;
|
@ -0,0 +1,16 @@
|
||||
ALTER TABLE `equipment`
|
||||
ADD COLUMN `equip_use` varchar(254);
|
||||
|
||||
UPDATE `equipment` SET `equip_use` = 'concerning';
|
||||
|
||||
ALTER TABLE `equipment`
|
||||
ALTER COLUMN `equip_use` SET NOT NULL;
|
||||
|
||||
|
||||
ALTER TABLE `organization`
|
||||
ADD COLUMN `org_use` varchar(254);
|
||||
|
||||
UPDATE `organization` SET `org_use` = 'correspondent';
|
||||
|
||||
ALTER TABLE `organization`
|
||||
ALTER COLUMN `org_use` SET NOT NULL;
|
@ -0,0 +1,16 @@
|
||||
ALTER TABLE "equipment"
|
||||
ADD COLUMN "equip_use" varchar(254);
|
||||
|
||||
UPDATE "equipment" SET "equip_use" = 'concerning';
|
||||
|
||||
ALTER TABLE "equipment"
|
||||
ALTER COLUMN "equip_use" SET NOT NULL;
|
||||
|
||||
|
||||
ALTER TABLE "organization"
|
||||
ADD COLUMN "org_use" varchar(254);
|
||||
|
||||
UPDATE "organization" SET "org_use" = 'correspondent';
|
||||
|
||||
ALTER TABLE "organization"
|
||||
ALTER COLUMN "org_use" SET NOT NULL;
|
@ -106,6 +106,12 @@ trait DoobieMeta extends EmilDoobieMeta {
|
||||
|
||||
implicit val metaPersonUse: Meta[PersonUse] =
|
||||
Meta[String].timap(PersonUse.unsafeFromString)(_.name)
|
||||
|
||||
implicit val metaEquipUse: Meta[EquipmentUse] =
|
||||
Meta[String].timap(EquipmentUse.unsafeFromString)(_.name)
|
||||
|
||||
implicit val metaOrgUse: Meta[OrgUse] =
|
||||
Meta[String].timap(OrgUse.unsafeFromString)(_.name)
|
||||
}
|
||||
|
||||
object DoobieMeta extends DoobieMeta {
|
||||
|
@ -15,7 +15,8 @@ case class REquipment(
|
||||
name: String,
|
||||
created: Timestamp,
|
||||
updated: Timestamp,
|
||||
notes: Option[String]
|
||||
notes: Option[String],
|
||||
use: EquipmentUse
|
||||
) {}
|
||||
|
||||
object REquipment {
|
||||
@ -28,7 +29,8 @@ object REquipment {
|
||||
val created = Column[Timestamp]("created", this)
|
||||
val updated = Column[Timestamp]("updated", this)
|
||||
val notes = Column[String]("notes", this)
|
||||
val all = NonEmptyList.of[Column[_]](eid, cid, name, created, updated, notes)
|
||||
val use = Column[EquipmentUse]("equip_use", this)
|
||||
val all = NonEmptyList.of[Column[_]](eid, cid, name, created, updated, notes, use)
|
||||
}
|
||||
|
||||
val T = Table(None)
|
||||
@ -41,7 +43,7 @@ object REquipment {
|
||||
.insert(
|
||||
t,
|
||||
t.all,
|
||||
fr"${v.eid},${v.cid},${v.name},${v.created},${v.updated},${v.notes}"
|
||||
fr"${v.eid},${v.cid},${v.name},${v.created},${v.updated},${v.notes},${v.use}"
|
||||
)
|
||||
}
|
||||
|
||||
@ -57,7 +59,8 @@ object REquipment {
|
||||
t.cid.setTo(v.cid),
|
||||
t.name.setTo(v.name),
|
||||
t.updated.setTo(now),
|
||||
t.notes.setTo(v.notes)
|
||||
t.notes.setTo(v.notes),
|
||||
t.use.setTo(v.use)
|
||||
)
|
||||
)
|
||||
} yield n
|
||||
@ -90,9 +93,17 @@ object REquipment {
|
||||
sql.query[REquipment].to[Vector]
|
||||
}
|
||||
|
||||
def findLike(coll: Ident, equipName: String): ConnectionIO[Vector[IdRef]] = {
|
||||
def findLike(
|
||||
coll: Ident,
|
||||
equipName: String,
|
||||
use: NonEmptyList[EquipmentUse]
|
||||
): ConnectionIO[Vector[IdRef]] = {
|
||||
val t = Table(None)
|
||||
run(select(t.eid, t.name), from(t), t.cid === coll && t.name.like(equipName))
|
||||
run(
|
||||
select(t.eid, t.name),
|
||||
from(t),
|
||||
t.cid === coll && t.name.like(equipName) && t.use.in(use)
|
||||
)
|
||||
.query[IdRef]
|
||||
.to[Vector]
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ case class ROrganization(
|
||||
notes: Option[String],
|
||||
created: Timestamp,
|
||||
updated: Timestamp,
|
||||
shortName: Option[String]
|
||||
shortName: Option[String],
|
||||
use: OrgUse
|
||||
) {}
|
||||
|
||||
object ROrganization {
|
||||
@ -43,6 +44,7 @@ object ROrganization {
|
||||
val created = Column[Timestamp]("created", this)
|
||||
val updated = Column[Timestamp]("updated", this)
|
||||
val shortName = Column[String]("short_name", this)
|
||||
val use = Column[OrgUse]("org_use", this)
|
||||
val all =
|
||||
NonEmptyList.of[Column[_]](
|
||||
oid,
|
||||
@ -55,7 +57,8 @@ object ROrganization {
|
||||
notes,
|
||||
created,
|
||||
updated,
|
||||
shortName
|
||||
shortName,
|
||||
use
|
||||
)
|
||||
}
|
||||
|
||||
@ -67,7 +70,7 @@ object ROrganization {
|
||||
DML.insert(
|
||||
T,
|
||||
T.all,
|
||||
fr"${v.oid},${v.cid},${v.name},${v.street},${v.zip},${v.city},${v.country},${v.notes},${v.created},${v.updated},${v.shortName}"
|
||||
fr"${v.oid},${v.cid},${v.name},${v.street},${v.zip},${v.city},${v.country},${v.notes},${v.created},${v.updated},${v.shortName},${v.use}"
|
||||
)
|
||||
|
||||
def update(v: ROrganization): ConnectionIO[Int] = {
|
||||
@ -84,7 +87,8 @@ object ROrganization {
|
||||
T.country.setTo(v.country),
|
||||
T.notes.setTo(v.notes),
|
||||
T.updated.setTo(now),
|
||||
T.shortName.setTo(v.shortName)
|
||||
T.shortName.setTo(v.shortName),
|
||||
T.use.setTo(v.use)
|
||||
)
|
||||
)
|
||||
for {
|
||||
@ -109,11 +113,17 @@ object ROrganization {
|
||||
sql.query[ROrganization].option
|
||||
}
|
||||
|
||||
def findLike(coll: Ident, orgName: String): ConnectionIO[Vector[IdRef]] =
|
||||
def findLike(
|
||||
coll: Ident,
|
||||
orgName: String,
|
||||
use: NonEmptyList[OrgUse]
|
||||
): ConnectionIO[Vector[IdRef]] =
|
||||
run(
|
||||
select(T.oid, T.name),
|
||||
from(T),
|
||||
T.cid === coll && (T.name.like(orgName) || T.shortName.like(orgName))
|
||||
T.cid === coll && (T.name.like(orgName) || T.shortName.like(orgName)) && T.use.in(
|
||||
use
|
||||
)
|
||||
)
|
||||
.query[IdRef]
|
||||
.to[Vector]
|
||||
|
Reference in New Issue
Block a user