Switching between development and production environment

Is there an easy way to switch between development and production profiles in appery.io? To separate development and production environment I can create two different databases in Appery.io. However, is there a way for us to switch the server codes between development and production easily?
1 person has
this question
+1
Reply
  • Junliang,

    We use a plugin to read the build number off of the executable running on the phone at startup.

    We then lookup the build number in a control table for each build .... one of the variables stored on that table is a Boolean for Test or prod.

    We switch the databases on the fly by reading the database keys off the control table ... and passing them to all of our database services , and we also pass the build number to server scripts that execute against the database ... the server scripts can then read the databaseid’s and the Test or prod indicators from the control table based on build number query.

    Make sense ?

    Hit tip ... use numeric build numbers ....

    Best,

    Bruce
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Hi Bruce,

    Thanks for the prompt reply. That idea is pretty good. Which plugin do you use for getting the build number?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Hello,

    Use the database to store this version is fine for the development stage, but it is not good for the production application because it requires an extra request to the database on each Server Code call. It is better to check a variable with the value = environment type (dev/prod)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Serhii and Junlaing,

    SInce different people will have different versions of the App on their phone - there has to be something coming directly FROM the phone, that's embedded in the .exe - to discern it from another version (the test or the production version of the app). Especially - once something hits the store - and you're still tweaking other versions (Testing on phones etc.) - you have to have something coming from the .exe to differentiate it from another version.

    BuildInfo does that.

    Here's the version I'm using:

    http://prntscr.com/i2bi2s

    Here's the source I'm using to retrieve AFTER device ready ... the LocalStorage variables are available after this function is called (sBuildNumber, sPackageName and sBundleID ) .... you can then use these 0 to lookup in your control table - if a build is in Production or Test...

    ffSetVersionandBundleID()

    function fSetVersionandBundleID() {

    try {

    fLocalSet('sBuildNumber', BuildInfo.version);

    fLocalSet('sPackageName', BuildInfo.basePackageName);

    fLocalSet('sBundleID', BuildInfo.basePackageName);

    fLocalSet('pushNotificationDeviceID', device.uuid )

    } catch (e) {

    fLocalSet('sBuildNumber', '085');

    localStorage.setItem('sPackageName', 'io.appery.northstar');

    localStorage.setItem('sBundleID', 'io.appery.northstar');

    }

    return;

    // Adding flocalSet - as it's used above....

    function fLocalSet(sMemVar, sValue) {
    // purpose - Simplify the syntax for setting a local memvar....
    //

    if (typeof(sValue) === 'object') {
    sValue = JSON.stringify(sValue);
    }
    return localStorage.setItem(sMemVar, sValue);
    }

    function fSetLocal(sMemVar, sValue) {
    return fLocalSet(sMemVar, sValue);
    }

    function fGetLocal(sMemVar, sType) {
    return fLocalGet(sMemVar, sType);
    }

    function fLocalGet(sMemVar, sType, uDefaultValue) {
    // Supported sType(s) are 'boolean', 'string' and 'numeric'.... otherwise - it will return the native...
    //
    var sWorkingReturn = localStorage.getItem(sMemVar);
    var uReturnValue;
    if (sWorkingReturn === null || sWorkingReturn === undefined || sWorkingReturn === 'null') {
    if (uDefaultValue === undefined) {
    sWorkingReturn = '';
    } else {
    uReturnValue = uDefaultValue;
    return uReturnValue;
    }
    }
    if (sType === undefined || sType === null) {
    sType = 'string';
    }
    if (sType === 'number') {
    sType = 'numeric';
    }

    switch (sType) {
    case 'string':
    {
    uReturnValue = sWorkingReturn;
    break;
    }
    case 'boolean':
    {
    if (sWorkingReturn !== 'true') {
    uReturnValue = false;
    } else {
    uReturnValue = true;
    }
    break;
    }

    case 'numeric':
    {
    if (sWorkingReturn === undefined || sWorkingReturn === null) {
    sWorkingReturn = '0';
    }
    uReturnValue = Number(sWorkingReturn);
    break;
    }

    case 'date':
    {
    // convert the date from it's store as a dbDate - into a date object....
    if (sWorkingReturn === undefined || sWorkingReturn === null || sWorkingReturn :
    {
    try {
    uReturnValue = JSON.parse(sWorkingReturn);
    } catch (e) {
    uReturnValue = [];
    }
    break;
    }

    default:
    {
    uReturnValue = sWorkingReturn;
    break;

    }
    }
    return uReturnValue;
    }

    Happy to help you implement this further - with the Structure of my control file - or even a dump from my control file - that you can load to yours....
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Hi Bruce,

    Do you place your control file (prod/dev indicators, version, database keys) in a "master" server code? How do you handle the switch of server codes to be used for dev/prod environments?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Hi Bruce,

    I included the BuildInfo plugin into our app. Initially it was working. However, at the moment we are encountering with problems such as the plug-in could not be detected. When we exported the project from appery.io into our Android Studio, the BuildInfo plugin is not exported together with the project. Do you also encounter this problem before?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Junliang,

    We’ve actually built our product in Appery on the Android side... but I’ll export and look today .

    What version if the Appery libraries are you using?

    Best,
    Bruce
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Also... To answer the previous question that I apparently missed... We handle the switching between production and Test....by putting the control file actually in a database... We then look up the build number in the database and that database table has an indicator on it as to whether that build is production or test... And it can be switched on the fly
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Junliang,

    Also, feel free to email me at Bruce.Stuart @the-Software-studio.com ....

    Best,
    Bruce
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated indifferent, undecided, unconcerned