Sandbox Database Seeder ¶
Sandbox seeder will bail with a warning if you attempt to run it in production.
Resetting a Docker Compose instance ¶
-
Backup database:
docker-compose exec db bash -c 'pg_dump -U$POSTGRES_USER --no-owner --no-acl $POSTGRES_DB' > ~/indevets.$(date +'%Y-%m-%d').sql
-
Open shell on database container
docker-compose exec db bash
-
Block new connections:
psql -U$POSTGRES_USER -d postgres -c "UPDATE pg_database SET datallowconn = 'false' WHERE datname = '$POSTGRES_DB'"
-
Disconnect everyone:
psql -U$POSTGRES_USER -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$POSTGRES_DB'"
-
Drop database:
dropdb -U$POSTGRES_USER $POSTGRES_DB
-
Create new empty database:
createdb -U$POSTGRES_USER $POSTGRES_DB
-
Exit db container shell:
exit
-
-
Run migrations:
docker-compose exec app artisan migrate
-
Open https://indevets.sandbox.jarv.us/sandboxsetup
- Click the refresh qbo token link
- Login with Intuit user
indevets
- Select company Team_Sandbox
- Click Next a bunch
- There’s no need to log into Core once redirected back
-
Run sandbox seeder:
docker-compose exec app artisan db:seed --class=SandboxDatabaseSeeder
Resetting a Kubernetes deployment ¶
-
Select namespace:
kubectl config set-context --current --namespace=indevets-staging
-
Backup database:
kubectl exec $(kubectl get pod -l app=core -o jsonpath='{.items[0].metadata.name}') \ -c core-db \ -- bash -c 'pg_dump -U$POSTGRES_USER --no-owner --no-acl $POSTGRES_DB' > ~/indevets.$(date +'%Y-%m-%d').sql
-
Open shell on database container
kubectl exec -it $(kubectl get pod -l app=core -o jsonpath='{.items[0].metadata.name}') \ -c core-db \ -- bash
-
Block new connections:
psql -U$POSTGRES_USER -d postgres -c \ "UPDATE pg_database SET datallowconn = 'false' WHERE datname = '$POSTGRES_DB'"
-
Disconnect everyone:
psql -U$POSTGRES_USER -d postgres -c \ "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$POSTGRES_DB'"
-
Drop database:
dropdb -U$POSTGRES_USER $POSTGRES_DB
-
Create new empty database:
createdb -U$POSTGRES_USER $POSTGRES_DB
-
Exit db container shell:
exit
-
-
Run migrations:
kubectl exec $(kubectl get pod -l app=core -o jsonpath='{.items[0].metadata.name}') \ -c core-app \ -- artisan migrate
-
Open https://staging.k8s-sandbox.indevets.com/sandboxsetup
- Click the refresh qbo token link
- Login with Intuit user
indevets
- Select company Team_Sandbox
- Click Next a bunch
- There’s no need to log into Core once redirected back
Tip
You can clone Quickbooks auth from https://staging.k8s-sandbox.indevets.com instead.
-
Run sandbox seeder:
kubectl exec $(kubectl get pod -l app=core -o jsonpath='{.items[0].metadata.name}') \ -c core-app \ -- artisan db:seed --class=SandboxDatabaseSeeder
Cloning Quickbooks auth between Kubernetes environments ¶
Quickbooks authentication can be copied from one Kubernetes deployment to another across namespaces, as an alternative to using the /sandboxsetup
web flow..
In this example, Quickbooks authentication is copied from https://staging.k8s-sandbox.indevets.com to pr-213:
from_namespace="indevets-staging"
from_label="app=core"
from_container="core-db"
to_namespace="indevets-sandbox"
to_label="app.kubernetes.io/instance=pr-213"
to_container="pr-213-psql"
from_pod=$(kubectl -n "${from_namespace}" get pod -l "${from_label}" -o jsonpath='{.items[0].metadata.name}')
to_pod=$(kubectl -n "${to_namespace}" get pod -l "${to_label}" -o jsonpath='{.items[0].metadata.name}')
kubectl -n "${from_namespace}" exec "${from_pod}" \
-c "${from_container}" \
-- bash -c 'pg_dump -U$POSTGRES_USER --no-owner --no-acl --clean --table=oauths $POSTGRES_DB' \
| kubectl -n "${to_namespace}" exec -i "${to_pod}" \
-c "${to_container}" \
-- bash -c 'psql -U$POSTGRES_USER $POSTGRES_DB'
How it works ¶
- the seeder will truncate known tables
- except, it will not truncate the Oauths table to preserve the tokens
- it will PullQuickbooks and Shifts
- it will cleanup orphan customers
- it will seed
None
andCancel
positions needed by Core - it will seed given users to facilitate testing (see Test Users)
- it will seed random users to fill in the data
- logging is performed at each step
Test Users ¶
The following users will always be available.
Role & login. All use password pass1234
:
- Super: michael@indevets.com
- Admin: sample-admin@example.com
- Vet: sample-vet@example.com
- Manager (Indie): indie-manager@example.com
- Manager (Multisite): multi-manager@example.com
Note:
- An Indie manager is also functionally equivelant to a Corp manager at this time.
example.com
is a safe IANA-managed technical domain; never receives email.
Integrated Accounts ¶
- QuickBooks Sandbox:
Team_Sandbox
- When I Work Workplace:
indevetstest
Inserting a Quickbooks token manually ¶
The sandbox seeder will preserve any existing oauth tokens while resetting tables, but will ultimately fail if no valid QBO token is available in the database–as will be the case in any fresh environment.
To inject a token manually, first use QuickBooks’ OAuth 2.0 Playground UI to obtain a new pair of access+refresh tokens. Choose IndeVets (sandbox)
for the app and Team_Sandbox
for the company when prompted.
App\Models\Oauth::create([
'provider' => 'quickbooks',
'access_token' => '<paste-access-token>',
'refresh_token' => '<paste-refresh-token>',
'state_token' => 12345678,
'realm_id' => 193514809217379,
'scope' => 'com.intuit.quickbooks.accounting',
'access_expires_at' => time()+3600,
'refresh_expires_at' => time()+8726400,
]);