Snowflake-Labs / schemachange

A Database Change Management tool for Snowflake
Apache License 2.0
517 stars 228 forks source link

How do I run SchemaChange with no deployment but with updating the change_history table ? #231

Open zroytman opened 9 months ago

zroytman commented 9 months ago

What are you trying to accomplish? I'm using the SchemaChange as part of our Azure DevOps pipeline. As we already have many DB objects deployed, I'm looking for the way to load the CHANGE_HISTORY table for the first time without deploying (compiling) the objects in the DB.

What options have you tried so far ? I've tried to run the SchemaChange in Dry Mode and expected to get exactly what I need, means updating the CHANGE_HISTORY table without compiling the DB objects themselves. In real, Dry Mode doesn't compile the objects (which is great) but doesn't update the CHANGE_HISTORY table too (which is bad for me).

So is there any way to run the SchemaChange in the mode in need? Any additional flag I missed?

Thanks.

michaeleyre commented 7 months ago

I have a similar problem. We have a list of SQL scripts that have already been executed in our development environment and we want to start using schema change, but we want to record the current scripts in the CHANGE_HISTORY table without executing them.

kotha commented 7 months ago

Hi, We ran into similar use case and followed these steps, using some python scripts.

  1. Generate DDL's for all the scripts using get_ddl
  2. Save the scripts into folders with pre-defined naming convention. We named files in such a way that they are executed in the order we need.
  3. Had another python script to scan all the files and generate the checksum (we used the function used in schemachange to make sure the same checksum is generated) hashlib.sha224(content.encode('utf-8')).hexdigest()

Insert the entries generated from the above step into the schema_change_history table

now apply schema change with dry-run: false and you should not see script changes getting applied Thanks

zroytman commented 7 months ago

@kotha Thanks. That is exactly what I did ;-)