Skip to content

Migrations on SQL Server#1372

Merged
pimeys merged 12 commits intomasterfrom
mssql-migrations
Dec 3, 2020
Merged

Migrations on SQL Server#1372
pimeys merged 12 commits intomasterfrom
mssql-migrations

Conversation

@pimeys
Copy link
Contributor

@pimeys pimeys commented Nov 16, 2020

Implements migrations on Microsoft SQL Server 2017 and 2019. Probably works with earlier versions from at least 2012, but we test only against 2017 and 2019. Removes the gatekeeper for SQL Server from the Migration Engine, and all hacky test macros, unifying the Microsoft databases to the test_all_connectors.

Closes: #813

I'm 99% sure this one fixes issues with raw queries containing stored procedures and transactions (reported in our Slack), and some issues we might've fixed with this PR include:

Closes: prisma/prisma#4333
Closes: prisma/prisma#4250

@pimeys pimeys force-pushed the mssql-migrations branch 5 times, most recently from c3f3068 to 494472e Compare November 20, 2020 16:46
@pimeys pimeys force-pushed the mssql-migrations branch 6 times, most recently from f6903d5 to 8996dd9 Compare December 1, 2020 12:31
@pimeys pimeys changed the title WIP: Migrations on SQL Server Migrations on SQL Server Dec 1, 2020
@pimeys pimeys added this to the 2.13.0 milestone Dec 1, 2020
@pimeys pimeys force-pushed the mssql-migrations branch 3 times, most recently from 7e4eed5 to 44880c6 Compare December 1, 2020 13:06
@pimeys pimeys force-pushed the mssql-migrations branch 2 times, most recently from 2c1857b to 39c0ca0 Compare December 1, 2020 13:46
Copy link
Contributor

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just starting to review

#[proc_macro_attribute]
pub fn test_each_connector_mssql(attr: TokenStream, input: TokenStream) -> TokenStream {
test_each_connector::test_each_connector_impl(attr, input, true)
test_each_connector::test_each_connector_impl(attr, input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@pimeys pimeys force-pushed the mssql-migrations branch 4 times, most recently from 86a2d32 to 8230965 Compare December 2, 2020 09:00
Copy link
Contributor

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving another batch of comments before I move to reviewing the diffing logic. Looking good so far!

.table_walkers()
.filter(move |t| t.table_index() != table_index)
.flat_map(|t| t.foreign_keys())
.filter(move |fk| fk.referenced_table().table_index() == table_index)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

.previous()
.table_walker_at(drop_index.table_index)
.index_at(drop_index.index_index),
)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pub name: String,
pub table_index: usize,
pub index_index: usize,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


/// Render a `DropIndex` step.
fn render_drop_index(&self, drop_index: &DropIndex) -> String;
fn render_drop_index(&self, index: &IndexWalker<'_>) -> String;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

.field("table_index", &self.table_index)
.finish()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Thanks for adding these

Copy link
Contributor

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a p p r o v e d

Julius de Bruijn and others added 9 commits December 3, 2020 16:28
For SQL Server, we want to recreate the primary key before recreating a
column that's part of it. We do not want this behavior on other
databases, thus adding a new flag to the flavour.
Much nicer and following the crate standards this way, without needing
to add a completely unnecessary constructor creation...
Also fixes one test to not re-create the whole table (to spawn warnings
on SQL Server). The barrel `types::primary` will make the column
autocomplete and the next migration removes the identity, spawning a
recreation of the whole table.
@pimeys pimeys merged commit 06e7855 into master Dec 3, 2020
@pimeys pimeys deleted the mssql-migrations branch December 3, 2020 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants