Skip to content

Commit

Permalink
ADD: table comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mc256 committed Jul 1, 2023
1 parent f69f601 commit bf2cef6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 14 additions & 3 deletions proxy/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"database/sql"
"encoding/json"
"fmt"
"math"
"path"
"time"

"github.com/containerd/containerd/log"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
Expand All @@ -19,9 +23,6 @@ import (
"github.com/mc256/starlight/util/common"
"github.com/mc256/starlight/util/send"
"github.com/pkg/errors"
"math"
"path"
"time"
)

type Database struct {
Expand Down Expand Up @@ -72,6 +73,7 @@ func (d *Database) InitDatabase() error {
);
comment on column image.nlayer is 'number of the non-empty layers';
comment on table image is 'Each row represents an image where (image, hash) is unique. Each layer references back to the id column of this table.';
create table if not exists layer
(
Expand All @@ -87,6 +89,10 @@ func (d *Database) InitDatabase() error {
on delete cascade
);
comment on column layer."stackIndex" is 'the index of the layer in the image';
comment on table layer is 'Each row represents a layer where (image, stackIndex) is unique. Each file references back to the id column of this table.';
create table if not exists filesystem
(
id serial,
Expand Down Expand Up @@ -119,6 +125,9 @@ func (d *Database) InitDatabase() error {
on delete cascade
);
comment on column file."order" is 'the order of the file in uploaded filesystem access traces';
comment on table file is 'Each row represents a file where (file, fs) is unique. Each row references to the filesystem table.';
create index if not exists fki_filesystem_fk
on file (fs);
Expand All @@ -135,6 +144,8 @@ func (d *Database) InitDatabase() error {
primary key (name, tag, platform)
);
comment on table tag is 'Each row represents a tag where (name, tag, platform) is unique. Each row references to the image table.';
`); err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions util/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ import (

func ExportToJsonFile(v interface{}, p string) error {
fh, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE, 0644)
defer fh.Close()
if err != nil {
return err
}
defer fh.Close()

buf, err := json.MarshalIndent(v, "", "\t")
if err != nil {
return err
}

_, _ = fh.Write(buf)
_, err = fh.Write(buf)
if err != nil {
return err
}

return nil
return fh.Sync()
}

0 comments on commit bf2cef6

Please sign in to comment.