protected static function update_permissions($ofs1, $ofs3) { foreach (dbx::get_schemas(dbsteward::$new_database) as $new_schema) { $old_schema = dbx::get_schema(dbsteward::$old_database, $new_schema['name']); foreach (dbx::get_permissions($new_schema) as $new_permission) { if ($old_schema == NULL || !mssql10_permission::has_permission($old_schema, $new_permission)) { $ofs1->write(mssql10_permission::get_sql(dbsteward::$new_database, $new_schema, $new_schema, $new_permission) . "\n"); } } foreach (dbx::get_tables($new_schema) as $new_table) { $old_table = NULL; if ($old_schema != NULL) { $old_table = dbx::get_table($old_schema, $new_table['name']); } if (!dbsteward::$ignore_oldnames && mssql10_diff_tables::is_renamed_table($new_schema, $new_table)) { // oldTableName renamed table ? skip permission diffing on it, it is the same continue; } foreach (dbx::get_permissions($new_table) as $new_permission) { if ($old_table == NULL || !mssql10_permission::has_permission($old_table, $new_permission)) { $ofs1->write(mssql10_permission::get_sql(dbsteward::$new_database, $new_schema, $new_table, $new_permission) . "\n"); } } } foreach (dbx::get_sequences($new_schema) as $new_sequence) { $old_sequence = NULL; if ($old_schema != NULL) { $old_sequence = dbx::get_sequence($old_schema, $new_sequence['name']); } foreach (dbx::get_permissions($new_sequence) as $new_permission) { if ($old_sequence == NULL || !mssql10_permission::has_permission($old_sequence, $new_permission)) { $ofs1->write(mssql10_permission::get_sql(dbsteward::$new_database, $new_schema, $new_sequence, $new_permission) . "\n"); } } } foreach (dbx::get_functions($new_schema) as $new_function) { $old_function = NULL; if ($old_schema != NULL) { $old_function = dbx::get_function($old_schema, $new_function['name'], mssql10_function::get_declaration($new_schema, $new_function)); } foreach (dbx::get_permissions($new_function) as $new_permission) { if ($old_function == NULL || !mssql10_permission::has_permission($old_function, $new_permission)) { $ofs1->write(mssql10_permission::get_sql(dbsteward::$new_database, $new_schema, $new_function, $new_permission) . "\n"); } } } foreach (dbx::get_views($new_schema) as $new_view) { $old_view = NULL; if ($old_schema != NULL) { $old_view = dbx::get_view($old_schema, $new_view['name']); } foreach (dbx::get_permissions($new_view) as $new_permission) { // if always_recreate_views flag is on, always grant all view permissions, as the view was recreated if (dbsteward::$always_recreate_views || $old_view == NULL || !mssql10_permission::has_permission($old_view, $new_permission) || mssql10_diff_views::is_view_modified($old_view, $new_view)) { // view permissions are in schema stage 3 file because views are (re)created in that stage for SELECT * expansion $ofs3->write(mssql10_permission::get_sql(dbsteward::$new_database, $new_schema, $new_view, $new_permission) . "\n"); } } } } }
public static function diff_constraints_table($ofs, $old_schema, $old_table, $new_schema, $new_table, $type, $drop_constraints = FALSE) { if ($drop_constraints) { // drop constraints that no longer exist or are modified foreach (mssql10_diff_tables::get_drop_constraints($old_schema, $old_table, $new_schema, $new_table, $type) as $constraint) { $ofs->write(mssql10_table::get_constraint_drop_sql($constraint) . "\n"); } } else { // if it is a renamed table, remove all constraints and recreate with new table name conventions if (mssql10_diff_tables::is_renamed_table($new_schema, $new_table)) { foreach (mssql10_constraint::get_table_constraints(dbsteward::$old_database, $old_schema, $old_table, $type) as $constraint) { // rewrite the constraint definer to refer to the new table name // so the constraint by the old name, but part of the new table // will be referenced properly in the drop statement $constraint['table_name'] = $new_table['name']; $ofs->write(mssql10_table::get_constraint_drop_sql($constraint) . "\n"); } // add all defined constraints back to the new table foreach (mssql10_constraint::get_table_constraints(dbsteward::$new_database, $new_schema, $new_table, $type) as $constraint) { $ofs->write(mssql10_table::get_constraint_sql($constraint) . "\n"); } return; } // END if it is a renamed table, remove all constraints and recreate with new table name conventions // add new constraints foreach (mssql10_diff_tables::get_new_constraints($old_schema, $old_table, $new_schema, $new_table, $type) as $constraint) { $ofs->write(mssql10_table::get_constraint_sql($constraint) . "\n"); } } }