Adding Modified By relation
This commit is contained in:
parent
dc1778a5b9
commit
e79ece15aa
@ -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:
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -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);")
|
||||||
|
@ -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);")
|
||||||
|
@ -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);")
|
||||||
|
@ -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);")
|
||||||
|
@ -11,12 +11,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CompanyData struct {
|
type CompanyData struct {
|
||||||
Id int `orm:"column(id);"`
|
Id int `orm:"column(id);"`
|
||||||
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"`
|
||||||
Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"`
|
ModifiedBy int64 `orm:"column(modifiedBy);"`
|
||||||
Modified time.Time `orm:"column(modified);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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *CompanyData) TableName() string {
|
func (t *CompanyData) TableName() string {
|
||||||
|
@ -11,12 +11,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CompanyUser struct {
|
type CompanyUser struct {
|
||||||
Id int `orm:"column(id);"`
|
Id int `orm:"column(id);"`
|
||||||
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)"`
|
||||||
Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"`
|
ModifiedBy int64 `orm:"column(modifiedBy);"`
|
||||||
Modified time.Time `orm:"column(modified);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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *CompanyUser) TableName() string {
|
func (t *CompanyUser) TableName() string {
|
||||||
|
@ -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"`
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
Id int `orm:"column(id);"`
|
Id int `orm:"column(id);"`
|
||||||
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)"`
|
||||||
Created time.Time `orm:"column(created);type(timestamp with time zone);auto_now_add"`
|
ModifiedBy int64 `orm:"column(modifiedBy);"`
|
||||||
Modified time.Time `orm:"column(modified);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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Post) TableName() string {
|
func (t *Post) TableName() string {
|
||||||
|
@ -84,7 +84,13 @@ func migrateDbName(dbName, migType string) {
|
|||||||
if migType != "" {
|
if migType != "" {
|
||||||
cmd = exec.Command(cmdString, "migrate", migType, connString, dir)
|
cmd = exec.Command(cmdString, "migrate", migType, connString, dir)
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command(cmdString, "migrate", connString, dir)
|
fmt.Println("no command")
|
||||||
|
if dir == "" {
|
||||||
|
cmd = exec.Command(cmdString, "migrate", connString)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command(cmdString, "migrate", connString, dir)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine stdout and stderr
|
// Combine stdout and stderr
|
||||||
|
Loading…
Reference in New Issue
Block a user