Skip to content

Instantly share code, notes, and snippets.

View petmongrels's full-sized avatar

Vivek Singh petmongrels

View GitHub Profile
@petmongrels
petmongrels / txt
Last active March 27, 2024 09:27
Run metabase locally
# 1. Start metabase
export MB_DB_TYPE=postgres
export MB_DB_DBNAME=avni_metabase
export MB_DB_PORT=5432
export MB_DB_USER=reporting_user
export MB_DB_PASS=password
export MB_DB_HOST=localhost
java -jar metabase.jar
# 2. Restore organisation data to database.
@petmongrels
petmongrels / gist:354a54ed1d0c3f492688d61c2dd63e55
Last active March 20, 2024 11:02
Embedded migration issue and solution options
Steps to reproduce the issue (program enrolment is used as example, it will happen with all entities)
1. Start with old schema database (181) on the client and then start with new version of the app (185, 7.0.x).
2. Let the migration run for a few seconds into the ProgramEncounter migration.
3. make stop_app
4. make open_db (see the obs in program enrolments are empty) and the schema for it is Embedded.
5. make start_app (see the schema version is 181) and migration runs again but it fails to make program enrolments observations non empty.
Reason.
In step 2 we do commit transaction. This commits the new (185) schema changes but not the schema version. Due the commit realm file gets changed. This was verified by throwing an error before transaction commit and open_db, the schema is not migrated in that case and data is all there. So because the schema gets changed, the observations becomes empty - treated like a new field.
In step 5 since the realm file has already changes the migration doesn't do anything fo
@petmongrels
petmongrels / gist:864af3e83307bc34bb4077ee3e319c8d
Last active February 16, 2024 07:19
Form Mapping Stack Trace
org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:314)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:507)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethod
@petmongrels
petmongrels / gist:684467ccb3cf617c0297f446a614f13c
Created February 13, 2024 12:42
using org.avni.server.util.ExceptionUtil#getFullStackTrace
java.lang.RuntimeException: java.lang.NullPointerException: fooFoo
at org.avni.server.util.ExceptionUtilTest.getFullStackTrace(ExceptionUtilTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
org.avni.server.util.ExceptionUtilTest.foo(ExceptionUtilTest.java:26)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
@petmongrels
petmongrels / scpt
Last active October 2, 2023 07:03
Annoying or necessary website reasons for now allowing copy paste in text field
-- Add beneficiary to bank account
repeat 1 times
delay 5
tell application "System Events" to keystroke "783432892348"
delay 3
tell application "System Events" to keystroke "783432892348"
delay 3
tell application "System Events" to keystroke "John Smith"
delay 5
make fill_text text=$1
sleep 3
make fill_text text=$2
@petmongrels
petmongrels / gist:58d51d1192dc9b92b61b91ea2876f492
Created September 4, 2023 15:33
Open files in react native stack trace from emulator
FILE="`echo $1 | cut -d':' -f 1`"
LINE_NUMBER="`echo $1 | cut -d':' -f 2`"
open -na "IntelliJ IDEA.app" --args --line $LINE_NUMBER $FILE
## Also set REACT_EDITOR env variable to this file
## if you call this file idea then
## export REACT_EDITOR=idea
-- create groups
begin transaction;
insert into groups (uuid, name, version, organisation_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time)
(select uuid_generate_v4(), 'Administrators', 1, id, 1, 1, current_timestamp, current_timestamp from organisation where id <> 1 and organisation.is_voided = false); -- 193
-- Without entity specific fields
insert into group_privilege (uuid, group_id, privilege_id, subject_type_id, program_id, program_encounter_type_id, encounter_type_id, checklist_detail_id, version, organisation_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time)
select uuid_generate_v4(), groups.id, privilege.id, null, null, null, null, null, 1, groups.organisation_id, 1, 1, current_timestamp, current_timestamp
from privilege join groups on groups.name = 'Administrators'
where privilege.entity_type in ('Report', 'NonTransaction', 'Task'); -- 29*193
DEBUG [6:29:08:633] [SelectFormElement::AC][Debug] Dispatching action: "EA.TOGGLE_SINGLESELECT_ANSWER"
DEBUG [6:29:08:645] [RuleService][Debug] Getting Rules of Type ViewFilter for Form - Observation Encounter ed2c239a-00ca-439c-8f2b-76543fdc55cf
DEBUG [6:29:08:685] [SelectFormElement::AC][Debug] Dispatched action completed: "EA.TOGGLE_SINGLESELECT_ANSWER"
DEBUG [6:29:08:691] [SyncComponent][Debug] SHOULD UPDATE
DEBUG [6:29:08:721] [ProgressBarView][Debug] SHOULD UPDATE
DEBUG [6:29:08:727] [IndividualEncounterView][Debug] render with IndividualUUID=undefined and EncounterTypeUUID=7664eab2-446e-4fc8-ac52-a77c4306893e
DEBUG [6:29:08:738] [AppHeader][Debug] SHOULD UPDATE
DEBUG [6:29:08:744] [PreviousEncounterPullDownView][Debug] SHOULD UPDATE
DEBUG [6:29:08:744] [PreviousEncounterPullDownView][Debug] render
DEBUG [6:29:08:745] [IndividualProfile][Debug] SHOULD UPDATE