MOBILE-4284 question: Drop unused DB columns
WebSQL doesn't support dropping columns, that's why we're migrating to a new table with the _2 suffix instead.
This commit is contained in:
		
							parent
							
								
									e87408418b
								
							
						
					
					
						commit
						391dfbdfcc
					
				| @ -12,16 +12,17 @@ | |||||||
| // See the License for the specific language governing permissions and
 | // See the License for the specific language governing permissions and
 | ||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
|  | import { SQLiteDB } from '@classes/sqlitedb'; | ||||||
| import { CoreSiteSchema } from '@services/sites'; | import { CoreSiteSchema } from '@services/sites'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Database variables for CoreQuestion service. |  * Database variables for CoreQuestion service. | ||||||
|  */ |  */ | ||||||
| export const QUESTION_TABLE_NAME = 'questions'; | export const QUESTION_TABLE_NAME = 'questions_2'; | ||||||
| export const QUESTION_ANSWERS_TABLE_NAME = 'question_answers'; | export const QUESTION_ANSWERS_TABLE_NAME = 'question_answers'; | ||||||
| export const QUESTION_SITE_SCHEMA: CoreSiteSchema = { | export const QUESTION_SITE_SCHEMA: CoreSiteSchema = { | ||||||
|     name: 'CoreQuestionProvider', |     name: 'CoreQuestionProvider', | ||||||
|     version: 1, |     version: 2, | ||||||
|     tables: [ |     tables: [ | ||||||
|         { |         { | ||||||
|             name: QUESTION_TABLE_NAME, |             name: QUESTION_TABLE_NAME, | ||||||
| @ -45,14 +46,6 @@ export const QUESTION_SITE_SCHEMA: CoreSiteSchema = { | |||||||
|                     name: 'componentid', |                     name: 'componentid', | ||||||
|                     type: 'INTEGER', |                     type: 'INTEGER', | ||||||
|                 }, |                 }, | ||||||
|                 { |  | ||||||
|                     name: 'userid', |  | ||||||
|                     type: 'INTEGER', |  | ||||||
|                 }, |  | ||||||
|                 { |  | ||||||
|                     name: 'number', |  | ||||||
|                     type: 'INTEGER', |  | ||||||
|                 }, |  | ||||||
|                 { |                 { | ||||||
|                     name: 'state', |                     name: 'state', | ||||||
|                     type: 'TEXT', |                     type: 'TEXT', | ||||||
| @ -102,6 +95,15 @@ export const QUESTION_SITE_SCHEMA: CoreSiteSchema = { | |||||||
|             primaryKeys: ['component', 'attemptid', 'name'], |             primaryKeys: ['component', 'attemptid', 'name'], | ||||||
|         }, |         }, | ||||||
|     ], |     ], | ||||||
|  |     async migrate(db: SQLiteDB, oldVersion: number): Promise<void> { | ||||||
|  |         if (oldVersion < 2) { | ||||||
|  |             await db.migrateTable( | ||||||
|  |                 'questions', | ||||||
|  |                 QUESTION_TABLE_NAME, | ||||||
|  |                 ({ component, componentid, attemptid, slot, state }) => ({ component, componentid, attemptid, slot, state }), | ||||||
|  |             ); | ||||||
|  |         } | ||||||
|  |     }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -112,8 +114,6 @@ export type CoreQuestionDBRecord = { | |||||||
|     attemptid: number; |     attemptid: number; | ||||||
|     slot: number; |     slot: number; | ||||||
|     componentid: number; |     componentid: number; | ||||||
|     userid: number; |  | ||||||
|     number?: number; // eslint-disable-line id-blacklist
 |  | ||||||
|     state: string; |     state: string; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -547,14 +547,11 @@ export class CoreQuestionProvider { | |||||||
|         state: string, |         state: string, | ||||||
|         siteId?: string, |         siteId?: string, | ||||||
|     ): Promise<void> { |     ): Promise<void> { | ||||||
| 
 |  | ||||||
|         const site = await CoreSites.getSite(siteId); |         const site = await CoreSites.getSite(siteId); | ||||||
|         const entry: CoreQuestionDBRecord = { |         const entry: CoreQuestionDBRecord = { | ||||||
|             component, |             component, | ||||||
|             componentid: componentId, |             componentid: componentId, | ||||||
|             attemptid: attemptId, |             attemptid: attemptId, | ||||||
|             userid: userId, |  | ||||||
|             number: question.number, // eslint-disable-line id-blacklist
 |  | ||||||
|             slot: question.slot, |             slot: question.slot, | ||||||
|             state: state, |             state: state, | ||||||
|         }; |         }; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user