Search code examples
google-app-enginepython-2.7jinja2webapp2wtforms

How to harmonize local dev environment with production?


My local environment and my production environment are not compatible anymore. The problem is that I'm using IDs and keys for an entity, region, where some of those keys are hardcoded and I can't get it out what has been hardcoded yet.

class City(db.Model):
  region = db.ReferenceProperty()
  name = db.StringProperty()

class Region(db.Model):
  name = db.StringProperty()
  countrycode = db.StringProperty()
  vieworder = db.IntegerProperty()
  areacode = db.IntegerProperty()
  areacodes = db.ListProperty(int)

Many regions and cities were populated in the production environment using the above model which appears to work. But I've been forced to hardcode these generated IDs on production when making inserts i.e.

  <select onchange="cities(this);document.getElementById('area').display='';" name="region" id="region">
                                <option value="">«{% trans %}Choose region{% endtrans %}»</option>
                                <option value="4703187">

                     Andaman &amp; Nicobar Islands
                </option>
<option value="4694186">

                     Andhra Pradesh
                </option>
<option value="4699188">

                     Arunachal Pradesh
                </option>
<option value="4692186">

                     Assam
                </option>
<option value="4702186">

                     Bihar
                </option>
<option value="4698185">

                     Chandigarh
                </option>
<option value="4676188">

                     Chhattisgarh
                </option>
<option value="4691190">

                     Dadra &amp; Nagar Haveli
                </option>
<option value="4704183">

                     Daman &amp; Diu
                </option>
<option value="4699183">

                     Delhi
                </option>
<option value="4702187">

                     Goa
                </option>
<option value="4691189">

                     Gujarat
                </option>
<option value="4700186">

                     Haryana
                </option>
<option value="4703185">

                     Himachal Pradesh
                </option>
<option value="4694187">

                     Jammu &amp; Kashmir
                </option>
<option value="4699189">

                     Jharkhand
                </option>
<option value="4701185">

                     Karnataka
                </option>
<option value="4695189">

                     Kerala
                </option>
<option value="4700189">

                     Lakshadweep
                </option>
<option value="4697186">

                     Madhya Pradesh
                </option>
<option value="4694184">

                     Maharashtra
                </option>
<option value="4700187">

                     Manipur
                </option>
<option value="4703186">

                     Meghalaya
                </option>
<option value="4698184">

                     Mizoram
                </option>
<option value="4692187">

                     Nagaland
                </option>
<option value="4696185">

                     Orissa
                </option>
<option value="4676189">

                     Pondicherry
                </option>
<option value="4693185">

                     Punjab
                </option>
<option value="4701186">

                     Rajasthan
                </option>
<option value="4701187">

                     Sikkim
                </option>
<option value="4701188">

                     Tamil Nadu
                </option>
<option value="4697187">

                     Tripura
                </option>
<option value="4699190">

                     Uttaranchal
                </option>
<option value="4692188">

                     Uttar Pradesh
                </option>
<option value="4700188">

                     West Bengal
                </option>

                        </select>

I use WTForms and some special enhancements so it's going to be tricky to get all the hardcoded IDs out of the system, is there anthing else smart that I can do to make m local envirnment work again, is it possible to import the regions and cities from production to local so that they have the same IDs? If yes, how can it be done? I also have this problem for categories whose IDs are hardcoded in a manner similar to above.


Solution

  • If you have hardcoded values, then by definition, they're going to be written down somewhere, so why can't you use the same list of values on both test and production servers? Or by hardcoded, do you mean, stored in a database?

    I think your question might really be, how can you export the datastore from the production datastore, and load it into your local test server, in which case, this related StackOverflow question should help : Export from AppEngine database to the local development database?