Skip to content

Commit

Permalink
Round 2 of allowing creation _timestamp in file declare for admins. (#31
Browse files Browse the repository at this point in the history
)

* include created_timestamp (if any) in insert

* getting timestamp all the way through
  • Loading branch information
marcmengel authored Mar 26, 2024
1 parent f14c775 commit fa689ce
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions metacat/db/dbobjects2.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,12 @@ def create(self, creator=None, transaction=None):
meta = json.dumps(self.Metadata or {})
checksums = json.dumps(self.Checksums or {})
transaction.execute("""
insert into files(id, namespace, name, metadata, size, checksums, creator) values(%s, %s, %s, %s, %s, %s, %s)
insert into files(id, namespace, name, metadata, size, checksums, creator, created_timestamp) values(%s, %s, %s, %s, %s, %s, %s, %s)
returning created_timestamp
""",
(self.FID, self.Namespace, self.Name, meta, self.Size, checksums, creator))
(self.FID, self.Namespace, self.Name, meta, self.Size, checksums, creator,

datetime.fromtimestamp(f.CreatedTimestamp).isoformat() if self.CreatedTimestamp else null))
self.CreatedTimestamp = c.fetchone()[0]
if self.Parents:
insert_many(self.DB,
Expand All @@ -533,14 +535,15 @@ def create_many(db, files, creator, transaction=None):
null = r"\N"
for f in files:
f.FID = f.FID or DBFile.generate_id()
files_csv.append("%s\t%s\t%s\t%s\t%s\t%s\t%s" % (
files_csv.append("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (
f.FID,
f.Namespace or null,
f.Name or null,
json.dumps(f.Metadata) if f.Metadata else '{}',
f.Size if f.Size is not None else null,
json.dumps(f.Checksums) if f.Checksums else '{}',
f.Creator or creator or null
f.Creator or creator or null,
datetime.fromtimestamp(f.CreatedTimestamp).isoformat() if f.CreatedTimestamp else null,
))
f.Creator = f.Creator or creator
if f.Parents:
Expand All @@ -550,7 +553,7 @@ def create_many(db, files, creator, transaction=None):
files_data = "\n".join(files_csv)
#open("/tmp/files.csv", "w").write(files_data)
transaction.copy_from(io.StringIO(files_data), "files",
columns = ["id", "namespace", "name", "metadata", "size", "checksums","creator"])
columns = ["id", "namespace", "name", "metadata", "size", "checksums","creator", "created_timestamp"])
transaction.copy_from(io.StringIO("\n".join(parents_csv)), "parent_child",
columns=["child_id", "parent_id"])

Expand Down

0 comments on commit fa689ce

Please sign in to comment.