forked from nyaruka/rp-indexer
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move a little more functionality into contacts package
- Loading branch information
1 parent
90bc8c1
commit be02daf
Showing
6 changed files
with
126 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
name: CI | ||
on: [push, pull_request] | ||
env: | ||
go-version: '1.16.x' | ||
es-version: '7.10.1' | ||
go-version: "1.16.x" | ||
es-version: "7.10.1" | ||
jobs: | ||
test: | ||
name: Test | ||
strategy: | ||
matrix: | ||
pg-version: ['12', '13'] | ||
pg-version: ["12", "13"] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
|
||
- name: Install ElasticSearch | ||
uses: nyaruka/elasticsearch-action@master | ||
with: | ||
elastic version: ${{ env.es-version }} | ||
- name: Install ElasticSearch | ||
uses: nyaruka/elasticsearch-action@master | ||
with: | ||
elastic version: ${{ env.es-version }} | ||
|
||
- name: Install PostgreSQL | ||
uses: harmon758/postgresql-action@v1 | ||
with: | ||
postgresql version: ${{ matrix.pg-version }} | ||
postgresql db: elastic_test | ||
postgresql user: temba | ||
postgresql password: temba | ||
- name: Install PostgreSQL | ||
uses: harmon758/postgresql-action@v1 | ||
with: | ||
postgresql version: ${{ matrix.pg-version }} | ||
postgresql db: elastic_test | ||
postgresql user: nyaruka | ||
postgresql password: nyaruka | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: ${{ env.go-version }} | ||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: ${{ env.go-version }} | ||
|
||
- name: Run tests | ||
run: go test -p=1 -coverprofile=coverage.text -covermode=atomic ./... | ||
- name: Run tests | ||
run: go test -p=1 -coverprofile=coverage.text -covermode=atomic ./... | ||
|
||
- name: Upload coverage | ||
if: success() | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
- name: Upload coverage | ||
if: success() | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
release: | ||
name: Release | ||
needs: [test] | ||
if: startsWith(github.ref, 'refs/tags/') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: ${{ env.go-version }} | ||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: ${{ env.go-version }} | ||
|
||
- name: Publish release | ||
uses: goreleaser/goreleaser-action@v1 | ||
with: | ||
version: v0.147.2 | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
fail_ci_if_error: true | ||
- name: Publish release | ||
uses: goreleaser/goreleaser-action@v1 | ||
with: | ||
version: v0.147.2 | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
fail_ci_if_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package contacts | ||
|
||
import ( | ||
"database/sql" | ||
"time" | ||
) | ||
|
||
const sqlSelectModified = ` | ||
SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM ( | ||
SELECT | ||
id, org_id, uuid, name, language, status, ticket_count AS tickets, is_active, created_on, modified_on, last_seen_on, | ||
EXTRACT(EPOCH FROM modified_on) * 1000000 as modified_on_mu, | ||
( | ||
SELECT array_to_json(array_agg(row_to_json(u))) | ||
FROM ( | ||
SELECT scheme, path | ||
FROM contacts_contacturn | ||
WHERE contact_id = contacts_contact.id | ||
) u | ||
) as urns, | ||
( | ||
SELECT jsonb_agg(f.value) | ||
FROM ( | ||
select case | ||
when value ? 'ward' | ||
then jsonb_build_object( | ||
'ward_keyword', trim(substring(value ->> 'ward' from '(?!.* > )([^>]+)')) | ||
) | ||
else '{}' :: jsonb | ||
end || district_value.value as value | ||
FROM ( | ||
select case | ||
when value ? 'district' | ||
then jsonb_build_object( | ||
'district_keyword', trim(substring(value ->> 'district' from '(?!.* > )([^>]+)')) | ||
) | ||
else '{}' :: jsonb | ||
end || state_value.value as value | ||
FROM ( | ||
select case | ||
when value ? 'state' | ||
then jsonb_build_object( | ||
'state_keyword', trim(substring(value ->> 'state' from '(?!.* > )([^>]+)')) | ||
) | ||
else '{}' :: jsonb | ||
end || | ||
jsonb_build_object('field', key) || value as value | ||
from jsonb_each(contacts_contact.fields) | ||
) state_value | ||
) as district_value | ||
) as f | ||
) as fields, | ||
( | ||
SELECT array_to_json(array_agg(g.uuid)) | ||
FROM ( | ||
SELECT contacts_contactgroup.uuid | ||
FROM contacts_contactgroup_contacts, contacts_contactgroup | ||
WHERE contact_id = contacts_contact.id AND | ||
contacts_contactgroup_contacts.contactgroup_id = contacts_contactgroup.id | ||
) g | ||
) as groups | ||
FROM contacts_contact | ||
WHERE modified_on >= $1 | ||
ORDER BY modified_on ASC | ||
LIMIT 500000 | ||
) t; | ||
` | ||
|
||
func FetchModified(db *sql.DB, lastModified time.Time) (*sql.Rows, error) { | ||
return db.Query(sqlSelectModified, lastModified) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package contacts | ||
|
||
import _ "embed" | ||
|
||
// settings and mappings for our index | ||
//go:embed index_settings.json | ||
var IndexSettings string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../utils/deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters