schemachange icon indicating copy to clipboard operation
schemachange copied to clipboard

Unit Test to verify version uniqueness

Open james-camacho-ab opened this issue 3 years ago • 3 comments

One issue we've run into is multiple users will use the same version, as an arbitrary example 20220127.1, within the branch and it causes problems when they want to merge because it won't get caught until they're about to merge their branch. Then one of the users will need to rename the file, which will reset the PR votes and cause in increase in the amount of time it takes for our PRs to go through. Do you have an example of any automated unit tests we could write so it gets caught as soon as the PR is submitted?

An even better solution would be if the workflow named or renamed the files, but reading through the readme it seems the files are meant to remain statically named

james-camacho-ab avatar Jan 27 '22 21:01 james-camacho-ab

We ran into the same issue, it would be great to have a mechanism to catch it early.

tsingh2k15 avatar Feb 27 '22 22:02 tsingh2k15

Hey there @james-camacho-ab, thanks for reaching out. schemachange does have a --dry-run option which can be used in a CI/CD pipeline triggered by PR creation. Would that work?

sfc-gh-jhansen avatar Mar 21 '22 20:03 sfc-gh-jhansen

@sfc-gh-jhansen @tsingh2k15 Our Software Engineering team ended up making some new workflow files that will change the file name when the PR is merged to the most recent version date + number. If it's a value add, here's the code that retrieves the file version:

args = parser.parse_args()

def get_version():
    con = snowflake.connector.connect(
        user = args.sf_user,
        password = args.sf_password,
        account = args.sf_account,
        role = args.sf_role,
        warehouse = args.sf_warehouse,
        database = 'ABI_TST'
    )
    cur = con.cursor()
    cur.execute("select top 1 script from ABI_TST.SCHEMACHANGE.CHANGE_HISTORY order by installed_on desc")
    return(cur.fetchone()[0])

latest_version = get_version()
print("latest version is ", latest_version)
subprocess.run(["echo", "::set-output name=latest_filename::", latest_version.strip()])

We can close out this issue. Thanks!

james-camacho-ab avatar Mar 21 '22 21:03 james-camacho-ab