mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Add updated
column to some tables
This commit is contained in:
@ -0,0 +1,29 @@
|
||||
-- organization
|
||||
ALTER TABLE `organization`
|
||||
ADD COLUMN (`updated` timestamp);
|
||||
|
||||
UPDATE `organization` SET `updated` = `created`;
|
||||
|
||||
ALTER TABLE `organization`
|
||||
MODIFY `updated` timestamp NOT NULL;
|
||||
|
||||
-- person
|
||||
ALTER TABLE `person`
|
||||
MODIFY `created` timestamp;
|
||||
|
||||
ALTER TABLE `person`
|
||||
ADD COLUMN (`updated` timestamp);
|
||||
|
||||
UPDATE `person` SET `updated` = `created`;
|
||||
|
||||
ALTER TABLE `person`
|
||||
MODIFY `updated` timestamp NOT NULL;
|
||||
|
||||
-- equipment
|
||||
ALTER TABLE `equipment`
|
||||
ADD COLUMN (`updated` timestamp);
|
||||
|
||||
UPDATE `equipment` SET `updated` = `created`;
|
||||
|
||||
ALTER TABLE `equipment`
|
||||
MODIFY `updated` timestamp NOT NULL;
|
@ -0,0 +1,29 @@
|
||||
-- organization
|
||||
ALTER TABLE "organization"
|
||||
ADD COLUMN "updated" timestamp;
|
||||
|
||||
UPDATE "organization" SET "updated" = "created";
|
||||
|
||||
ALTER TABLE "organization"
|
||||
ALTER COLUMN "updated" SET NOT NULL;
|
||||
|
||||
-- person
|
||||
ALTER TABLE "person" ALTER COLUMN "created"
|
||||
TYPE timestamp USING(to_timestamp("created", 'YYYY-MM-DD HH24:MI:SS')::timestamp);
|
||||
|
||||
ALTER TABLE "person"
|
||||
ADD COLUMN "updated" timestamp;
|
||||
|
||||
UPDATE "person" SET "updated" = "created";
|
||||
|
||||
ALTER TABLE "person"
|
||||
ALTER COLUMN "updated" SET NOT NULL;
|
||||
|
||||
-- equipment
|
||||
ALTER TABLE "equipment"
|
||||
ADD COLUMN "updated" timestamp;
|
||||
|
||||
UPDATE "equipment" SET "updated" = "created";
|
||||
|
||||
ALTER TABLE "equipment"
|
||||
ALTER COLUMN "updated" SET NOT NULL;
|
@ -7,7 +7,13 @@ import docspell.store.impl._
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
|
||||
case class REquipment(eid: Ident, cid: Ident, name: String, created: Timestamp) {}
|
||||
case class REquipment(
|
||||
eid: Ident,
|
||||
cid: Ident,
|
||||
name: String,
|
||||
created: Timestamp,
|
||||
updated: Timestamp
|
||||
) {}
|
||||
|
||||
object REquipment {
|
||||
|
||||
@ -18,25 +24,32 @@ object REquipment {
|
||||
val cid = Column("cid")
|
||||
val name = Column("name")
|
||||
val created = Column("created")
|
||||
val all = List(eid, cid, name, created)
|
||||
val updated = Column("updated")
|
||||
val all = List(eid, cid, name, created, updated)
|
||||
}
|
||||
import Columns._
|
||||
|
||||
def insert(v: REquipment): ConnectionIO[Int] = {
|
||||
val sql = insertRow(table, all, fr"${v.eid},${v.cid},${v.name},${v.created}")
|
||||
val sql =
|
||||
insertRow(table, all, fr"${v.eid},${v.cid},${v.name},${v.created},${v.updated}")
|
||||
sql.update.run
|
||||
}
|
||||
|
||||
def update(v: REquipment): ConnectionIO[Int] = {
|
||||
val sql = updateRow(
|
||||
table,
|
||||
and(eid.is(v.eid), cid.is(v.cid)),
|
||||
commas(
|
||||
cid.setTo(v.cid),
|
||||
name.setTo(v.name)
|
||||
def sql(now: Timestamp) =
|
||||
updateRow(
|
||||
table,
|
||||
and(eid.is(v.eid), cid.is(v.cid)),
|
||||
commas(
|
||||
cid.setTo(v.cid),
|
||||
name.setTo(v.name),
|
||||
updated.setTo(now)
|
||||
)
|
||||
)
|
||||
)
|
||||
sql.update.run
|
||||
for {
|
||||
now <- Timestamp.current[ConnectionIO]
|
||||
n <- sql(now).update.run
|
||||
} yield n
|
||||
}
|
||||
|
||||
def existsByName(coll: Ident, ename: String): ConnectionIO[Boolean] = {
|
||||
|
@ -19,7 +19,8 @@ case class ROrganization(
|
||||
city: String,
|
||||
country: String,
|
||||
notes: Option[String],
|
||||
created: Timestamp
|
||||
created: Timestamp,
|
||||
updated: Timestamp
|
||||
) {}
|
||||
|
||||
object ROrganization {
|
||||
@ -38,7 +39,8 @@ object ROrganization {
|
||||
val country = Column("country")
|
||||
val notes = Column("notes")
|
||||
val created = Column("created")
|
||||
val all = List(oid, cid, name, street, zip, city, country, notes, created)
|
||||
val updated = Column("updated")
|
||||
val all = List(oid, cid, name, street, zip, city, country, notes, created, updated)
|
||||
}
|
||||
|
||||
import Columns._
|
||||
@ -47,26 +49,31 @@ object ROrganization {
|
||||
val sql = insertRow(
|
||||
table,
|
||||
all,
|
||||
fr"${v.oid},${v.cid},${v.name},${v.street},${v.zip},${v.city},${v.country},${v.notes},${v.created}"
|
||||
fr"${v.oid},${v.cid},${v.name},${v.street},${v.zip},${v.city},${v.country},${v.notes},${v.created},${v.updated}"
|
||||
)
|
||||
sql.update.run
|
||||
}
|
||||
|
||||
def update(v: ROrganization): ConnectionIO[Int] = {
|
||||
val sql = updateRow(
|
||||
table,
|
||||
and(oid.is(v.oid), cid.is(v.cid)),
|
||||
commas(
|
||||
cid.setTo(v.cid),
|
||||
name.setTo(v.name),
|
||||
street.setTo(v.street),
|
||||
zip.setTo(v.zip),
|
||||
city.setTo(v.city),
|
||||
country.setTo(v.country),
|
||||
notes.setTo(v.notes)
|
||||
def sql(now: Timestamp) =
|
||||
updateRow(
|
||||
table,
|
||||
and(oid.is(v.oid), cid.is(v.cid)),
|
||||
commas(
|
||||
cid.setTo(v.cid),
|
||||
name.setTo(v.name),
|
||||
street.setTo(v.street),
|
||||
zip.setTo(v.zip),
|
||||
city.setTo(v.city),
|
||||
country.setTo(v.country),
|
||||
notes.setTo(v.notes),
|
||||
updated.setTo(now)
|
||||
)
|
||||
)
|
||||
)
|
||||
sql.update.run
|
||||
for {
|
||||
now <- Timestamp.current[ConnectionIO]
|
||||
n <- sql(now).update.run
|
||||
} yield n
|
||||
}
|
||||
|
||||
def existsByName(coll: Ident, oname: String): ConnectionIO[Boolean] =
|
||||
|
@ -20,7 +20,8 @@ case class RPerson(
|
||||
country: String,
|
||||
notes: Option[String],
|
||||
concerning: Boolean,
|
||||
created: Timestamp
|
||||
created: Timestamp,
|
||||
updated: Timestamp
|
||||
) {}
|
||||
|
||||
object RPerson {
|
||||
@ -40,7 +41,20 @@ object RPerson {
|
||||
val notes = Column("notes")
|
||||
val concerning = Column("concerning")
|
||||
val created = Column("created")
|
||||
val all = List(pid, cid, name, street, zip, city, country, notes, concerning, created)
|
||||
val updated = Column("updated")
|
||||
val all = List(
|
||||
pid,
|
||||
cid,
|
||||
name,
|
||||
street,
|
||||
zip,
|
||||
city,
|
||||
country,
|
||||
notes,
|
||||
concerning,
|
||||
created,
|
||||
updated
|
||||
)
|
||||
}
|
||||
|
||||
import Columns._
|
||||
@ -49,27 +63,32 @@ object RPerson {
|
||||
val sql = insertRow(
|
||||
table,
|
||||
all,
|
||||
fr"${v.pid},${v.cid},${v.name},${v.street},${v.zip},${v.city},${v.country},${v.notes},${v.concerning},${v.created}"
|
||||
fr"${v.pid},${v.cid},${v.name},${v.street},${v.zip},${v.city},${v.country},${v.notes},${v.concerning},${v.created},${v.updated}"
|
||||
)
|
||||
sql.update.run
|
||||
}
|
||||
|
||||
def update(v: RPerson): ConnectionIO[Int] = {
|
||||
val sql = updateRow(
|
||||
table,
|
||||
and(pid.is(v.pid), cid.is(v.cid)),
|
||||
commas(
|
||||
cid.setTo(v.cid),
|
||||
name.setTo(v.name),
|
||||
street.setTo(v.street),
|
||||
zip.setTo(v.zip),
|
||||
city.setTo(v.city),
|
||||
country.setTo(v.country),
|
||||
concerning.setTo(v.concerning),
|
||||
notes.setTo(v.notes)
|
||||
def sql(now: Timestamp) =
|
||||
updateRow(
|
||||
table,
|
||||
and(pid.is(v.pid), cid.is(v.cid)),
|
||||
commas(
|
||||
cid.setTo(v.cid),
|
||||
name.setTo(v.name),
|
||||
street.setTo(v.street),
|
||||
zip.setTo(v.zip),
|
||||
city.setTo(v.city),
|
||||
country.setTo(v.country),
|
||||
concerning.setTo(v.concerning),
|
||||
notes.setTo(v.notes),
|
||||
updated.setTo(now)
|
||||
)
|
||||
)
|
||||
)
|
||||
sql.update.run
|
||||
for {
|
||||
now <- Timestamp.current[ConnectionIO]
|
||||
n <- sql(now).update.run
|
||||
} yield n
|
||||
}
|
||||
|
||||
def existsByName(coll: Ident, pname: String): ConnectionIO[Boolean] =
|
||||
|
Reference in New Issue
Block a user