1
0
mirror of https://github.com/jbranchaud/til synced 2026-03-04 15:08:45 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
jbranchaud
fecf11684a Add Transition A Branch From One Base To Another as a Git TIL 2022-10-02 10:59:29 -05:00
jbranchaud
777239db24 Add Change Existing Column To Not Null as a MySQL TIL 2022-10-02 09:53:54 -05:00
3 changed files with 53 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1249 TILs and counting..._
_1251 TILs and counting..._
---
@@ -317,6 +317,7 @@ _1249 TILs and counting..._
- [Stashing Only Unstaged Changes](git/stashing-only-unstaged-changes.md)
- [Stashing Untracked Files](git/stashing-untracked-files.md)
- [Switch To A Recent Branch With FZF](git/switch-to-a-recent-branch-with-fzf.md)
- [Transition A Branch From One Base To Another](git/transition-a-branch-from-one-base-to-another.md)
- [Turn Off The Output Pager For One Command](git/turn-off-the-output-pager-for-one-command.md)
- [Two Kinds Of Dotted Range Notation](git/two-kinds-of-dotted-range-notation.md)
- [Unstage Changes Wih Git Restore](git/unstage-changes-with-git-restore.md)
@@ -522,6 +523,7 @@ _1249 TILs and counting..._
### MySQL
- [Change Existing Column To Not Null](mysql/change-existing-column-to-not-null.md)
- [Default Username And Password For New Instance](mysql/default-username-and-password-for-new-instance.md)
- [Display Output In A Vertical Format](mysql/display-output-in-a-vertical-format.md)
- [Doing Date Math](mysql/doing-date-math.md)

View File

@@ -0,0 +1,23 @@
# Transition A Branch From One Base To Another
Let's say I'm working in a git workflow where we have `main` as our production
branch and `dev` as our development branch. I've opened a feature branch off of
`main` and made a series of commits. It is at that point that I realize I
should instead be branched off `dev`. I could open up a new branch off `dev`
and then `cherry-pick` those commits. That is messier and more steps than
necessary.
Instead, I can transition the feature branch I'm already working from to a
different base.
The [`git-rebase`](https://git-scm.com/docs/git-rebase) command supports this
with the `--onto` flag.
```bash
$ git rebase --onto dev main my-feature-branch
```
Specify the new base branch (`dev`), the current base (`main`), and then the
name of the branch you are transitioning (`my-feature-branch`).
[source](https://stackoverflow.com/a/10853956/535590)

View File

@@ -0,0 +1,27 @@
# Change Existing Column To Not Null
Let's say you have an existing nullable column. You want to update the schema
to enforce a `not null` constraint on that column. You can do that with an
[`alter table`](https://dev.mysql.com/doc/refman/8.0/en/alter-table.html) DDL
statement. You can do this with the `modify` or `change` option.
With `modify` you redeclare the column definition with the options that you
want. You'll need to know and specify the existing data type of that column.
```sql
alter table books modify publication_year int not null;
```
It is possible, but clumsy to do this with the `change` option because you
declare the column name twice. That's because `change` is typically used to
rename a column.
```sql
alter table books change publication_year publication_year int not null;
```
If you're updating a column for a table that already contains data, make a plan
to backfill any existing records that have `null` for that column. Every record
will need a value in that column before the `modify` can be applied.
[source](https://stackoverflow.com/a/6305252/535590)