Adding Modified By relation

This commit is contained in:
Lukas Bachschwell 2018-11-16 13:37:18 +01:00
parent dc1778a5b9
commit e79ece15aa
14 changed files with 38 additions and 24 deletions

View File

@ -24,7 +24,7 @@ Todo till we can fork this repo
* ~~company delete needs to exist and update usercompanymap~~ * ~~company delete needs to exist and update usercompanymap~~
* ~~last modified in update for all tables~~ * ~~last modified in update for all tables~~
* checking some roles in all endpoints * checking some roles in all endpoints
* modified by relation (companyuserid) * modifiedby (companyuserid) relation
* return error in case of not found * return error in case of not found
## Notes: ## Notes:

View File

@ -139,6 +139,7 @@ func (c *CompanyDataController) Put() {
id, _ := strconv.Atoi(idStr) id, _ := strconv.Atoi(idStr)
v := models.CompanyData{Id: id} v := models.CompanyData{Id: id}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
v.ModifiedBy = int64(currentUser.Id)
if err := models.UpdateCompanyDataById(o, &v); err == nil { if err := models.UpdateCompanyDataById(o, &v); err == nil {
c.ServeJSONSuccess("Ok") c.ServeJSONSuccess("Ok")
} else { } else {

View File

@ -189,6 +189,7 @@ func (c *CompanyUserController) Put() {
id, _ := strconv.Atoi(idStr) id, _ := strconv.Atoi(idStr)
v := models.CompanyUser{Id: id} v := models.CompanyUser{Id: id}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
v.ModifiedBy = int64(currentUser.Id)
if err := models.UpdateCompanyUserById(o, &v); err == nil { if err := models.UpdateCompanyUserById(o, &v); err == nil {
c.ServeJSONSuccess("Ok") c.ServeJSONSuccess("Ok")
} else { } else {

View File

@ -140,6 +140,7 @@ func (c *ContactController) Put() {
id, _ := strconv.Atoi(idStr) id, _ := strconv.Atoi(idStr)
v := models.Contact{Id: id} v := models.Contact{Id: id}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
v.ModifiedBy = int64(currentUser.Id)
if err := models.UpdateContactById(o, &v); err == nil { if err := models.UpdateContactById(o, &v); err == nil {
c.ServeJSONSuccess("Ok") c.ServeJSONSuccess("Ok")
} else { } else {

View File

@ -149,6 +149,7 @@ func (c *PostController) Put() {
id, _ := strconv.Atoi(idStr) id, _ := strconv.Atoi(idStr)
v := models.Post{Id: id} v := models.Post{Id: id}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil { if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
v.ModifiedBy = int64(currentUser.Id)
if err := models.UpdatePostById(o, &v); err == nil { if err := models.UpdatePostById(o, &v); err == nil {
c.ServeJSONSuccess("Updated Post") c.ServeJSONSuccess("Updated Post")
} else { } else {

View File

@ -20,7 +20,7 @@ func init() {
// Run the migrations // Run the migrations
func (m *CompanyUser_20181114_181043) Up() { func (m *CompanyUser_20181114_181043) Up() {
// use m.SQL("CREATE TABLE ...") to make schema update // use m.SQL("CREATE TABLE ...") to make schema update
m.SQL("CREATE TABLE public.company_user ( id integer NOT NULL, name text NOT NULL, role smallint NOT NULL, profile jsonb NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") m.SQL("CREATE TABLE public.company_user ( id integer NOT NULL, name text NOT NULL, role smallint NOT NULL, profile jsonb NOT NULL, \"modifiedBy\" bigint NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);")
m.SQL("CREATE SEQUENCE public.\"companyUser_id_seq\" AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") m.SQL("CREATE SEQUENCE public.\"companyUser_id_seq\" AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;")
m.SQL("ALTER SEQUENCE public.\"companyUser_id_seq\" OWNED BY public.company_user.id;") m.SQL("ALTER SEQUENCE public.\"companyUser_id_seq\" OWNED BY public.company_user.id;")
m.SQL("ALTER TABLE ONLY public.company_user ALTER COLUMN id SET DEFAULT nextval('public.\"companyUser_id_seq\"'::regclass);") m.SQL("ALTER TABLE ONLY public.company_user ALTER COLUMN id SET DEFAULT nextval('public.\"companyUser_id_seq\"'::regclass);")

View File

@ -20,7 +20,7 @@ func init() {
// Run the migrations // Run the migrations
func (m *CompanyData_20181114_181913) Up() { func (m *CompanyData_20181114_181913) Up() {
// use m.SQL("CREATE TABLE ...") to make schema update // use m.SQL("CREATE TABLE ...") to make schema update
m.SQL("CREATE TABLE public.company_data ( id integer NOT NULL, key text NOT NULL, value text, data jsonb, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") m.SQL("CREATE TABLE public.company_data ( id integer NOT NULL, key text NOT NULL, value text, data jsonb, \"modifiedBy\" bigint NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);")
m.SQL("CREATE SEQUENCE public.\"companyData_id_seq\" AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") m.SQL("CREATE SEQUENCE public.\"companyData_id_seq\" AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;")
m.SQL("ALTER SEQUENCE public.\"companyData_id_seq\" OWNED BY public.company_data.id;") m.SQL("ALTER SEQUENCE public.\"companyData_id_seq\" OWNED BY public.company_data.id;")
m.SQL("ALTER TABLE ONLY public.company_data ALTER COLUMN id SET DEFAULT nextval('public.\"companyData_id_seq\"'::regclass);") m.SQL("ALTER TABLE ONLY public.company_data ALTER COLUMN id SET DEFAULT nextval('public.\"companyData_id_seq\"'::regclass);")

View File

@ -20,7 +20,7 @@ func init() {
// Run the migrations // Run the migrations
func (m *Post_20181114_181919) Up() { func (m *Post_20181114_181919) Up() {
// use m.SQL("CREATE TABLE ...") to make schema update // use m.SQL("CREATE TABLE ...") to make schema update
m.SQL("CREATE TABLE public.post ( id integer NOT NULL, name text, data text NOT NULL, meta jsonb NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") m.SQL("CREATE TABLE public.post ( id integer NOT NULL, name text, data text NOT NULL, meta jsonb NOT NULL, \"modifiedBy\" bigint NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);")
m.SQL("CREATE SEQUENCE public.post_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") m.SQL("CREATE SEQUENCE public.post_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;")
m.SQL("ALTER SEQUENCE public.post_id_seq OWNED BY public.post.id;") m.SQL("ALTER SEQUENCE public.post_id_seq OWNED BY public.post.id;")
m.SQL("ALTER TABLE ONLY public.post ALTER COLUMN id SET DEFAULT nextval('public.post_id_seq'::regclass);") m.SQL("ALTER TABLE ONLY public.post ALTER COLUMN id SET DEFAULT nextval('public.post_id_seq'::regclass);")

View File

@ -20,7 +20,7 @@ func init() {
// Run the migrations // Run the migrations
func (m *Contact_20181114_181923) Up() { func (m *Contact_20181114_181923) Up() {
// use m.SQL("CREATE TABLE ...") to make schema update // use m.SQL("CREATE TABLE ...") to make schema update
m.SQL("CREATE TABLE public.contact ( id integer NOT NULL, \"firstName\" text, \"lastName\" text NOT NULL, \"phoneNumber\" text, email text, \"lastContact\" date, meta jsonb NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);") m.SQL("CREATE TABLE public.contact ( id integer NOT NULL, \"firstName\" text, \"lastName\" text NOT NULL, \"phoneNumber\" text, email text, \"lastContact\" date, meta jsonb NOT NULL, \"modifiedBy\" bigint NOT NULL, created timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL);")
m.SQL("CREATE SEQUENCE public.contact_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;") m.SQL("CREATE SEQUENCE public.contact_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;")
m.SQL("ALTER SEQUENCE public.contact_id_seq OWNED BY public.contact.id;") m.SQL("ALTER SEQUENCE public.contact_id_seq OWNED BY public.contact.id;")
m.SQL("ALTER TABLE ONLY public.contact ALTER COLUMN id SET DEFAULT nextval('public.contact_id_seq'::regclass);") m.SQL("ALTER TABLE ONLY public.contact ALTER COLUMN id SET DEFAULT nextval('public.contact_id_seq'::regclass);")

View File

@ -15,6 +15,7 @@ type CompanyData struct {
Key string `orm:"column(key)"` Key string `orm:"column(key)"`
Value string `orm:"column(value);null"` Value string `orm:"column(value);null"`
Data string `orm:"column(data);null"` Data string `orm:"column(data);null"`
ModifiedBy int64 `orm:"column(modifiedBy);"`
Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"` Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"`
Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"` Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"`
} }

View File

@ -15,6 +15,7 @@ type CompanyUser struct {
Name string `orm:"column(name)"` Name string `orm:"column(name)"`
Role int16 `orm:"column(role)"` Role int16 `orm:"column(role)"`
Profile string `orm:"column(profile)"` Profile string `orm:"column(profile)"`
ModifiedBy int64 `orm:"column(modifiedBy);"`
Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"` Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"`
Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"` Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"`
} }

View File

@ -18,6 +18,7 @@ type Contact struct {
Email string `orm:"column(email);null"` Email string `orm:"column(email);null"`
LastContact time.Time `orm:"column(lastContact);type(date);null"` LastContact time.Time `orm:"column(lastContact);type(date);null"`
Meta string `orm:"column(meta)"` Meta string `orm:"column(meta)"`
ModifiedBy int64 `orm:"column(modifiedBy);"`
Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"` Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"`
Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"` Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"`
} }

View File

@ -15,6 +15,7 @@ type Post struct {
Name string `orm:"column(name);null"` Name string `orm:"column(name);null"`
Data string `orm:"column(data)"` Data string `orm:"column(data)"`
Meta string `orm:"column(meta)"` Meta string `orm:"column(meta)"`
ModifiedBy int64 `orm:"column(modifiedBy);"`
Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"` Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"`
Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"` Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"`
} }

View File

@ -83,8 +83,14 @@ func migrateDbName(dbName, migType string) {
var cmd *exec.Cmd var cmd *exec.Cmd
if migType != "" { if migType != "" {
cmd = exec.Command(cmdString, "migrate", migType, connString, dir) cmd = exec.Command(cmdString, "migrate", migType, connString, dir)
} else {
fmt.Println("no command")
if dir == "" {
cmd = exec.Command(cmdString, "migrate", connString)
} else { } else {
cmd = exec.Command(cmdString, "migrate", connString, dir) cmd = exec.Command(cmdString, "migrate", connString, dir)
}
} }
// Combine stdout and stderr // Combine stdout and stderr