Automating Migration from SQL Server Authentication to OAuth for Tabular Models: A Python Solution

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

Introduction: The transition from SQL Server Authentication (SSA) to OAuth for our tabular modernization journey required changes in our legacy tabular models. These models used SQL queries in import tables, which are now required to be changed to M queries to implement OAuth authentication. This paper discusses the challenges faced during this migration and presents a Python script as a solution to automate the conversion process.

Background: Tabular models are structured as BIM files containing various elements like data sources, measures, relationships, dimensions, queries, and roles in a nested JSON format. Changing the data sources from SQL server auth (SSA) which requires hardcoded username and passwords to OAuth which works on AAD required us to change various import statements from SQL to M compatible code as plain SQL is not supported in OAuth.  Converting the SQL queries to M queries manually within this nested JSON structure is laborious and prone to errors.

Solution: To address this issue, we developed a Python script that utilizes JSON libraries to parse the BIM files and employs an intelligent iterator to locate and modify legacy SQL queries to M queries automatically. The script operates in two phases: Phase-1 creates M queries for all objects, and Phase-2 replaces old elements in the BIM File's nested JSON with new M query elements while eliminating unnecessary ones. The result is a BIM file compliant with OAuth authentication.

Benefits: Using our Python script eliminates the need for manual intervention, significantly reducing the chances of errors. The script has been successfully employed to migrate all our legacy tabular models, ensuring its reliability and effectiveness. In a large model with 64 tables, the manual migration process would take approximately 7 days and with 7 such models it can go up to 20-30 days. However, with our script, this task can be completed in a matter of seconds, resulting in a considerable reduction in time and effort.

Conclusion: Our customized Python script proved to be a valuable solution for our migration needs. This script holds the potential to serve as a migration tool for a seamless transition from SQL Server Authentication to OAuth for your tabular models.

Code Base: Please clone this Git repo and start using the script for your migration needs.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.