Convert migration from python to SQL