transistorsoft / background-geolocation-console

A field-testing & analysis server for the Background Geolocation plugin
MIT License
150 stars 157 forks source link

psql function to reformat Device.device_model and populate Device.framework #93

Closed christocracy closed 4 years ago

christocracy commented 4 years ago

We need a psql script to iterate devices table and populate the framework column where null

An old style device_model takes the form:

device_model framework
Moto G (5) Plus (ReactNative) null

Where Framework takes the form:

We need to find that text FrameworkName, remove it (including brackets) from device_model and use it to populate framework.

device_model framework
Moto G (5) Plus react-native
Sigura commented 4 years ago
update public.devices set
  device_model = trim(REGEXP_REPLACE(device_model, '^([^(]*).*$', '\1')),
  framework = (
    CASE trim(REGEXP_REPLACE(device_model, '^[^(]*\(([^)]*)\)$', '\1'))
        WHEN 'ReactNative' THEN 'react-native'
        WHEN 'Cordova' THEN 'cordova'
        WHEN 'Flutter' THEN 'flutter'
        ELSE null
    END
  )
where framework is null;
christocracy commented 4 years ago

Sample data after execute:

Sigura commented 4 years ago

Looks like all is fine and we can close this issue?