diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e4fb3d7fc..d9b4a08e7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -236,4 +236,19 @@ The same process is followed whether the contributor is external or a maintainer Once all tests are passing and the pull request has been approved by the appropriate code owners, a maintainer will merge the changes into `main`. +### Migrating an existing pull request into the monorepo + +You may have opened your pull request against an adapter prior to its migration into the monorepo. +In that case, you'll need to migrate that pull request into this repo. +Unfortunately, GitHub does not allow you to migrate a pull request; however, you can migrate your branch. +Here are the steps to do that: + +1. Fork this repository if you haven't already and pull it down locally +2. Run the script `./scripts/migrate-branch.sh` (replacing the args with your versions): + ```shell + source ./scripts/migrate-branch.sh dbt-labs dbt-postgres my-cool-feature-branch + ``` +3. Push your new feature branch back up to your fork of this repository +4. Open up a new pull request into `dbt-adapters` from your fork + And that's it! Happy developing :tada: diff --git a/scripts/backport-to-legacy-repo.sh b/scripts/backport-to-legacy-repo.sh new file mode 100644 index 000000000..e0b5dea64 --- /dev/null +++ b/scripts/backport-to-legacy-repo.sh @@ -0,0 +1,33 @@ +# 1. Run this script to backport a change from the monorepo to a legacy repo, e.g.: +# > source ./scripts/backport-to-legacy-repo.sh dbt-postgres 1.9.latest abc1234 +# 2. Resolve any conflicts resulting from the cherry pick. +# In particular, git will not know to move a new file out of the package directory and into the root. + +ADAPTER=$1 # the repo name (e.g. dbt-postgres) +BRANCH=$2 # the target branch (e.g. 1.9.latest) +COMMIT=$3 # the commit SHA to backport + +# add a new remote for the legacy repo +git remote add adapter https://github.com/dbt-labs/$ADAPTER.git +git fetch + +# create a new branch off of the target branch +git switch adapter/$BRANCH +git switch -c adapter/backport-$COMMIT-to-$BRANCH + +# cherry pick the commit from dbt-adapters into the new branch +git cherry-pick $COMMIT -x + +# manually resolve any conflicts and move new files where they need to be +# in particular, new files will not be moved automatically since there is no reference in the target repo + +# continue the cherry pick process after resolving conflicts +git cherry-pick --continue -e + +# :x! to accept the message + +# push the new branch up to the legacy repo +git push adapter backport-$COMMIT-to-$BRANCH + +# remove the remote that was created during this process +git remote remove adapter || true diff --git a/scripts/migrate-adapter.sh b/scripts/migrate-adapter.sh index 9993476cd..f5e50fd77 100644 --- a/scripts/migrate-adapter.sh +++ b/scripts/migrate-adapter.sh @@ -1,17 +1,17 @@ -repo=$1 -source_branch=$2 -target_branch=$3 +ADAPTER=$1 +SOURCE_BRANCH=$2 +TARGET_BRANCH=$3 # create a remote for the legacy adapter repo and fetch the latest commits -git remote remove old || true -git remote add old https://github.com/dbt-labs/$repo.git -git fetch old +git remote remove adapter || true +git remote add adapter https://github.com/dbt-labs/$ADAPTER.git +git fetch adapter # merge the updated branch from the legacy repo into the dbt-adapters repo -git checkout $target_branch -git merge old/$source_branch --allow-unrelated-histories +git checkout $TARGET_BRANCH +git merge adapter/$SOURCE_BRANCH --allow-unrelated-histories # remove the remote that was created by this process -git remote remove old || true +git remote remove adapter || true # manually clean up duplication or unwanted files diff --git a/scripts/migrate-branch.sh b/scripts/migrate-branch.sh new file mode 100644 index 000000000..367f358fb --- /dev/null +++ b/scripts/migrate-branch.sh @@ -0,0 +1,27 @@ +# 1. Run this script to migrate your feature branch from an adapter repo/fork to the dbt-adapters repo/fork, e.g.: +# > source ./scripts/migrate-branch.sh dbt-labs dbt-postgres my-cool-feature-branch +# 2. Resolve any conflicts resulting from the rebase. + +USER=$1 # your github user (e.g. dbt-labs) +ADAPTER=$2 # the repo name (e.g. dbt-postgres) +BRANCH=$3 # your feature branch (e.g. my-cool-feature-branch) + +# create a remote for the adapter repo (supports forks) +git remote add adapter https://github.com/$USER/$ADAPTER.git || true # this may already exist from a previous run + +# update your feature branch against dbt-adapters@main and potentially resolve conflicts +git fetch adapter +git rebase main adapter/$BRANCH + +# create a branch in the dbt-adapters repo for your feature branch from the adapter repo +git checkout -b $ADAPTER/$BRANCH # prefixing / namespaces your feature branch in the new repo +git merge adapter/$BRANCH + +# manually resolve any conflicts and move new files where they need to be +# in particular, new files will not be moved automatically since there is no reference in the target repo + +# push the new branch up to the legacy repo +git push adapter $BRANCH + +# remove the remote that was created during this process +git remote remove adapter || true