Skip to content

Commit f36604f

Browse files
authored
Merge pull request #836 from nyaruka/remove_contact_created_by_modified_by
Stop writing `Contact.created_by` and `modified_by` as these are nullable
2 parents aa84706 + 5526edc commit f36604f

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

Diff for: backends/rapidpro/contact.go

+5-13
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,21 @@ type Contact struct {
5252
CreatedOn_ time.Time `db:"created_on"`
5353
ModifiedOn_ time.Time `db:"modified_on"`
5454

55-
CreatedBy_ int `db:"created_by_id"`
56-
ModifiedBy_ int `db:"modified_by_id"`
57-
5855
IsNew_ bool
5956
}
6057

6158
// UUID returns the UUID for this contact
6259
func (c *Contact) UUID() courier.ContactUUID { return c.UUID_ }
6360

64-
const insertContactSQL = `
61+
const sqlInsertContact = `
6562
INSERT INTO
66-
contacts_contact(org_id, is_active, status, uuid, created_on, modified_on, created_by_id, modified_by_id, name, ticket_count)
67-
VALUES(:org_id, TRUE, 'A', :uuid, :created_on, :modified_on, :created_by_id, :modified_by_id, :name, 0)
68-
RETURNING id
69-
`
63+
contacts_contact( org_id, is_active, status, uuid, created_on, modified_on, name, ticket_count)
64+
VALUES(:org_id, TRUE, 'A', :uuid, :created_on, :modified_on, :name, 0)
65+
RETURNING id`
7066

7167
// insertContact inserts the passed in contact, the id field will be populated with the result on success
7268
func insertContact(tx *sqlx.Tx, contact *Contact) error {
73-
rows, err := tx.NamedQuery(insertContactSQL, contact)
69+
rows, err := tx.NamedQuery(sqlInsertContact, contact)
7470
if err != nil {
7571
return err
7672
}
@@ -166,10 +162,6 @@ func contactForURN(ctx context.Context, b *backend, org OrgID, channel *Channel,
166162
}
167163
}
168164

169-
// TODO: Set these to a system user
170-
contact.CreatedBy_ = 1
171-
contact.ModifiedBy_ = 1
172-
173165
// insert it
174166
tx, err := b.db.BeginTxx(ctx, nil)
175167
if err != nil {

Diff for: backends/rapidpro/schema.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ CREATE TABLE contacts_contact (
3636
uuid character varying(36) NOT NULL,
3737
name character varying(128),
3838
language character varying(3),
39-
created_by_id integer NOT NULL,
40-
modified_by_id integer NOT NULL,
39+
created_by_id integer,
40+
modified_by_id integer,
4141
org_id integer references orgs_org(id) on delete cascade
4242
);
4343

0 commit comments

Comments
 (0)