Zhi Kai
Zhi Kai

Reputation: 1587

Android: Controlling of DB Versions

As I am working on a project that involves multiple developers, and we are using DVCS, each developer will be working on a feature branch assigned to them. That being said, the feature branches are branched out from the latest develop branch. In the develop branch, the db version in the DatabaseHandler is

private static final int DATABASE_VERSION = 2;

In my feature branch, I am required to make a new table. So I have to increase the version to 3, so I can include the following in onUpgrade to execute the CREATE_APPLIANCE_TABLE statement.

@Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d("Database onUpgrade", "Old is: " + oldVersion + ". New is: " + newVersion);
        switch(oldVersion) {
            case 1:
            db.execSQL(CREATE_USER);
        case 2:
            db.execSQL(CREATE_APPLIANCE_ACTIVITY); // for version 3
    }
}

My concern is, what if another developer needs to make a new table too, and he carries out the same process as me. Do he increase the version in his feature branch to 3? And if so, what should be our next step when either or both of us close our feature branch and merged it into develop? Since we both edited the same file, there may be chance of conflict. So in the develop branch, do the version stay at 3, or?

Thanks in advance. :)

Upvotes: 1

Views: 61

Answers (2)

Ritesh Gune
Ritesh Gune

Reputation: 16729

As I understand, Whenever two developers work on the same file , at the time of merging branches last one to pull the changes will get the conflict in that file. So the last developer to pull changes can merge the changes manually after resolving all the conflicts.

In your case if version on develop is 2(Assuming version in market apk is 2) then next release version (market apk) for all branches will be 3, provided all features are included in that release.

Upvotes: 1

Oleg Skidan
Oleg Skidan

Reputation: 617

As I understand your questions. When you will merge your code files, you can put all your and his tables creating in one database version. Like that:

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.d("Database onUpgrade", "Old is: " + oldVersion + ". New is: " + newVersion);
    switch(oldVersion) {
        case **N**:
        db.execSQL(CREATE_YOUR_DATABASE); 
        db.execSQL(CREATE_HIS_DATABASE);
}

Upvotes: 2

Related Questions