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~~
|
||||
* ~~last modified in update for all tables~~
|
||||
* checking some roles in all endpoints
|
||||
* modified by relation (companyuserid)
|
||||
* modifiedby (companyuserid) relation
|
||||
* return error in case of not found
|
||||
|
||||
## Notes:
|
||||
|
@ -139,6 +139,7 @@ func (c *CompanyDataController) Put() {
|
||||
id, _ := strconv.Atoi(idStr)
|
||||
v := models.CompanyData{Id: id}
|
||||
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
|
||||
v.ModifiedBy = int64(currentUser.Id)
|
||||
if err := models.UpdateCompanyDataById(o, &v); err == nil {
|
||||
c.ServeJSONSuccess("Ok")
|
||||
} else {
|
||||
|
@ -189,6 +189,7 @@ func (c *CompanyUserController) Put() {
|
||||
id, _ := strconv.Atoi(idStr)
|
||||
v := models.CompanyUser{Id: id}
|
||||
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
|
||||
v.ModifiedBy = int64(currentUser.Id)
|
||||
if err := models.UpdateCompanyUserById(o, &v); err == nil {
|
||||
c.ServeJSONSuccess("Ok")
|
||||
} else {
|
||||
|
@ -140,6 +140,7 @@ func (c *ContactController) Put() {
|
||||
id, _ := strconv.Atoi(idStr)
|
||||
v := models.Contact{Id: id}
|
||||
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
|
||||
v.ModifiedBy = int64(currentUser.Id)
|
||||
if err := models.UpdateContactById(o, &v); err == nil {
|
||||
c.ServeJSONSuccess("Ok")
|
||||
} else {
|
||||
|
@ -149,6 +149,7 @@ func (c *PostController) Put() {
|
||||
id, _ := strconv.Atoi(idStr)
|
||||
v := models.Post{Id: id}
|
||||
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
|
||||
v.ModifiedBy = int64(currentUser.Id)
|
||||
if err := models.UpdatePostById(o, &v); err == nil {
|
||||
c.ServeJSONSuccess("Updated Post")
|
||||
} else {
|
||||
|
@ -20,7 +20,7 @@ func init() {
|
||||
// Run the migrations
|
||||
func (m *CompanyUser_20181114_181043) Up() {
|
||||
// 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("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);")
|
||||
|
@ -20,7 +20,7 @@ func init() {
|
||||
// Run the migrations
|
||||
func (m *CompanyData_20181114_181913) Up() {
|
||||
// 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("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);")
|
||||
|
@ -20,7 +20,7 @@ func init() {
|
||||
// Run the migrations
|
||||
func (m *Post_20181114_181919) Up() {
|
||||
// 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("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);")
|
||||
|
@ -20,7 +20,7 @@ func init() {
|
||||
// Run the migrations
|
||||
func (m *Contact_20181114_181923) Up() {
|
||||
// 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("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);")
|
||||
|
@ -15,6 +15,7 @@ type CompanyData struct {
|
||||
Key string `orm:"column(key)"`
|
||||
Value string `orm:"column(value);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"`
|
||||
Modified time.Time `orm:"column(modified);type(timestamp with time zone);auto_now_add"`
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ type CompanyUser struct {
|
||||
Name string `orm:"column(name)"`
|
||||
Role int16 `orm:"column(role)"`
|
||||
Profile string `orm:"column(profile)"`
|
||||
ModifiedBy int64 `orm:"column(modifiedBy);"`
|
||||
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"`
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ type Contact struct {
|
||||
Email string `orm:"column(email);null"`
|
||||
LastContact time.Time `orm:"column(lastContact);type(date);null"`
|
||||
Meta string `orm:"column(meta)"`
|
||||
ModifiedBy int64 `orm:"column(modifiedBy);"`
|
||||
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"`
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ type Post struct {
|
||||
Name string `orm:"column(name);null"`
|
||||
Data string `orm:"column(data)"`
|
||||
Meta string `orm:"column(meta)"`
|
||||
ModifiedBy int64 `orm:"column(modifiedBy);"`
|
||||
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"`
|
||||
}
|
||||
|
@ -83,8 +83,14 @@ func migrateDbName(dbName, migType string) {
|
||||
var cmd *exec.Cmd
|
||||
if migType != "" {
|
||||
cmd = exec.Command(cmdString, "migrate", migType, connString, dir)
|
||||
} else {
|
||||
fmt.Println("no command")
|
||||
if dir == "" {
|
||||
cmd = exec.Command(cmdString, "migrate", connString)
|
||||
} else {
|
||||
cmd = exec.Command(cmdString, "migrate", connString, dir)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Combine stdout and stderr
|
||||
|
Loading…
Reference in New Issue
Block a user