Skip to content

Stop writing Contact.created_by and modified_by as these are nullable #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions backends/rapidpro/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,21 @@ type Contact struct {
CreatedOn_ time.Time `db:"created_on"`
ModifiedOn_ time.Time `db:"modified_on"`

CreatedBy_ int `db:"created_by_id"`
ModifiedBy_ int `db:"modified_by_id"`

IsNew_ bool
}

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

const insertContactSQL = `
const sqlInsertContact = `
INSERT INTO
contacts_contact(org_id, is_active, status, uuid, created_on, modified_on, created_by_id, modified_by_id, name, ticket_count)
VALUES(:org_id, TRUE, 'A', :uuid, :created_on, :modified_on, :created_by_id, :modified_by_id, :name, 0)
RETURNING id
`
contacts_contact( org_id, is_active, status, uuid, created_on, modified_on, name, ticket_count)
VALUES(:org_id, TRUE, 'A', :uuid, :created_on, :modified_on, :name, 0)
RETURNING id`

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

// TODO: Set these to a system user
contact.CreatedBy_ = 1
contact.ModifiedBy_ = 1

// insert it
tx, err := b.db.BeginTxx(ctx, nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions backends/rapidpro/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ CREATE TABLE contacts_contact (
uuid character varying(36) NOT NULL,
name character varying(128),
language character varying(3),
created_by_id integer NOT NULL,
modified_by_id integer NOT NULL,
created_by_id integer,
modified_by_id integer,
org_id integer references orgs_org(id) on delete cascade
);

Expand Down