/* ================================================================= */ static void create_taxtable_tables( GncSqlBackend* be ) { gint version; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TT_TABLE_NAME ); if ( version == 0 ) { gnc_sql_create_table( be, TT_TABLE_NAME, TT_TABLE_VERSION, tt_col_table ); } else if ( version == 1 ) { /* Upgrade 64 bit int handling */ gnc_sql_upgrade_table( be, TT_TABLE_NAME, tt_col_table ); gnc_sql_set_table_version( be, TT_TABLE_NAME, TT_TABLE_VERSION ); } version = gnc_sql_get_table_version( be, TTENTRIES_TABLE_NAME ); if ( version == 0 ) { gnc_sql_create_table( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION, ttentries_col_table ); } else if ( version == 1 ) { /* Upgrade 64 bit int handling */ gnc_sql_upgrade_table( be, TTENTRIES_TABLE_NAME, ttentries_col_table ); gnc_sql_set_table_version( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION ); } }
static void create_recurrence_tables( GncSqlBackend* be ) { gint version; gboolean ok; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TABLE_NAME ); if ( version == 0 ) { (void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table ); } else if ( version < TABLE_VERSION ) { /* Upgrade: 1->2: Add recurrence_weekend_adjust field (mandatory, non-null field) */ if ( version == 1 ) { upgrade_recurrence_table_1_2 (be); } (void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION ); PINFO("Recurrence table upgraded from version %d to version %d\n", version, TABLE_VERSION); } }
/* ================================================================= */ static void create_lots_tables( GncSqlBackend* be ) { gint version; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TABLE_NAME ); if ( version == 0 ) { /* The table doesn't exist, so create it */ (void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table ); } else if ( version == 1 ) { /* Version 1 -> 2 removes the 'NOT NULL' constraint on the account_guid field. Create a temporary table, copy the data from the old table, delete the old table, then rename the new one. */ gnc_sql_upgrade_table( be, TABLE_NAME, col_table ); (void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION ); PINFO("Lots table upgraded from version 1 to version %d\n", TABLE_VERSION); } }
/* ================================================================= */ static void create_job_tables( GncSqlBackend* be ) { gint version; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TABLE_NAME ); if ( version == 0 ) { gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table ); } }
/* ================================================================= */ static void create_commodities_tables( GncSqlBackend* be ) { gint version; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, COMMODITIES_TABLE ); if ( version == 0 ) { (void)gnc_sql_create_table( be, COMMODITIES_TABLE, TABLE_VERSION, col_table ); } }
/* ================================================================= */ static void create_slots_tables( GncSqlBackend* be ) { gint version; gboolean ok; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TABLE_NAME ); if ( version == 0 ) { (void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table ); ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } } else if ( version < TABLE_VERSION ) { /* Upgrade: 1->2: 64-bit int values to proper definition, add index 2->3: Add gdate field */ if ( version == 1 ) { gnc_sql_upgrade_table( be, TABLE_NAME, col_table ); ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } } else if ( version == 2 ) { ok = gnc_sql_add_columns_to_table( be, TABLE_NAME, gdate_col_table ); if ( !ok ) { PERR( "Unable to add gdate column\n" ); } } (void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION ); PINFO("Slots table upgraded from version %d to version %d\n", version, TABLE_VERSION); } }
/* ================================================================= */ static void create_prices_tables( GncSqlBackend* be ) { gint version; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TABLE_NAME ); if ( version == 0 ) { (void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table ); } else if ( version == 1 ) { /* Upgrade 64 bit int handling */ gnc_sql_upgrade_table( be, TABLE_NAME, col_table ); (void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION ); } }
/* ================================================================= */ static void create_customer_tables( GncSqlBackend* be ) { gint version; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TABLE_NAME ); if ( version == 0 ) { gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table ); } else if ( version == 1 ) { /* Upgrade 64 bit int handling */ gnc_sql_upgrade_table( be, TABLE_NAME, col_table ); gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION ); PINFO("Customers table upgraded from version 1 to version %d\n", TABLE_VERSION); } }
/* ================================================================= */ static void create_invoice_tables( GncSqlBackend* be ) { gint version; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TABLE_NAME ); if ( version == 0 ) { gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table ); } else if ( version < TABLE_VERSION ) { /* Upgrade: 1->2: 64 bit int handling 2->3: invoice open date can be NULL */ gnc_sql_upgrade_table( be, TABLE_NAME, col_table ); gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION ); PINFO("Invoices table upgraded from version %d to version %d\n", version, TABLE_VERSION); } }
/** * Creates the transaction and split tables. * * @param be SQL backend */ static void create_transaction_tables( GncSqlBackend* be ) { gint version; gboolean ok; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TRANSACTION_TABLE ); if ( version == 0 ) { (void)gnc_sql_create_table( be, TRANSACTION_TABLE, TX_TABLE_VERSION, tx_col_table ); ok = gnc_sql_create_index( be, "tx_post_date_index", TRANSACTION_TABLE, post_date_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } } else if ( version < TX_TABLE_VERSION ) { /* Upgrade: 1->2: 64 bit int handling 2->3: allow dates to be NULL */ gnc_sql_upgrade_table( be, TRANSACTION_TABLE, tx_col_table ); (void)gnc_sql_set_table_version( be, TRANSACTION_TABLE, TX_TABLE_VERSION ); PINFO("Transactions table upgraded from version %d to version %d\n", version, TX_TABLE_VERSION); } version = gnc_sql_get_table_version( be, SPLIT_TABLE ); if ( version == 0 ) { (void)gnc_sql_create_table( be, SPLIT_TABLE, SPLIT_TABLE_VERSION, split_col_table ); ok = gnc_sql_create_index( be, "splits_tx_guid_index", SPLIT_TABLE, tx_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } ok = gnc_sql_create_index( be, "splits_account_guid_index", SPLIT_TABLE, account_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } } else if ( version < SPLIT_TABLE_VERSION ) { /* Upgrade: 1->2: 64 bit int handling 3->4: Split reconcile date can be NULL */ gnc_sql_upgrade_table( be, SPLIT_TABLE, split_col_table ); ok = gnc_sql_create_index( be, "splits_tx_guid_index", SPLIT_TABLE, tx_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } ok = gnc_sql_create_index( be, "splits_account_guid_index", SPLIT_TABLE, account_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } (void)gnc_sql_set_table_version( be, SPLIT_TABLE, SPLIT_TABLE_VERSION ); PINFO("Splits table upgraded from version %d to version %d\n", version, SPLIT_TABLE_VERSION); } }