Skip to content

Commit 6e38a60

Browse files
committed
Revert "Stop writing Contact.created_by and modified_by as these are nullable"
This reverts commit 5526edc.
1 parent f36604f commit 6e38a60

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Diff for: backends/rapidpro/contact.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,25 @@ 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+
5558
IsNew_ bool
5659
}
5760

5861
// UUID returns the UUID for this contact
5962
func (c *Contact) UUID() courier.ContactUUID { return c.UUID_ }
6063

61-
const sqlInsertContact = `
64+
const insertContactSQL = `
6265
INSERT INTO
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`
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+
`
6670

6771
// insertContact inserts the passed in contact, the id field will be populated with the result on success
6872
func insertContact(tx *sqlx.Tx, contact *Contact) error {
69-
rows, err := tx.NamedQuery(sqlInsertContact, contact)
73+
rows, err := tx.NamedQuery(insertContactSQL, contact)
7074
if err != nil {
7175
return err
7276
}
@@ -162,6 +166,10 @@ func contactForURN(ctx context.Context, b *backend, org OrgID, channel *Channel,
162166
}
163167
}
164168

169+
// TODO: Set these to a system user
170+
contact.CreatedBy_ = 1
171+
contact.ModifiedBy_ = 1
172+
165173
// insert it
166174
tx, err := b.db.BeginTxx(ctx, nil)
167175
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,
40-
modified_by_id integer,
39+
created_by_id integer NOT NULL,
40+
modified_by_id integer NOT NULL,
4141
org_id integer references orgs_org(id) on delete cascade
4242
);
4343

0 commit comments

Comments
 (0)