Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Reset modtime to zero in migration scripts
Browse files Browse the repository at this point in the history
This prevents a lot of unnecessary diffs when running go generate.
Migration logic must not use modtime anyway.
  • Loading branch information
cevian committed Apr 7, 2020
1 parent b827b62 commit b505854
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
43 changes: 40 additions & 3 deletions pkg/pgmodel/migrations/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,50 @@
package main

import (
"github.com/shurcooL/vfsgen"
"log"
"net/http"

"github.com/shurcooL/vfsgen"
"os"
"time"
)

var Assets http.FileSystem = http.Dir("sql")
// modTimeFS is an http.FileSystem wrapper that modifies
// underlying fs such that all of its file mod times are set to zero.
type modTimeFS struct {
fs http.FileSystem
}

func (fs modTimeFS) Open(name string) (http.File, error) {
f, err := fs.fs.Open(name)
if err != nil {
return nil, err
}
return modTimeFile{f}, nil
}

type modTimeFile struct {
http.File
}

func (f modTimeFile) Stat() (os.FileInfo, error) {
fi, err := f.File.Stat()
if err != nil {
return nil, err
}
return modTimeFileInfo{fi}, nil
}

type modTimeFileInfo struct {
os.FileInfo
}

func (modTimeFileInfo) ModTime() time.Time {
return time.Time{}
}

var Assets http.FileSystem = modTimeFS{
fs: http.Dir("sql"),
}

func main() {
err := vfsgen.Generate(Assets, vfsgen.Options{
Expand Down

0 comments on commit b505854

Please sign in to comment.