Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LQDN Adminsys
don
Commits
38baf090
Commit
38baf090
authored
Dec 13, 2018
by
Okhin
Browse files
Let's have an up and down migration
parent
070ca0af
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
db/migrations/20181213125806_add_parent_field.php
View file @
38baf090
...
...
@@ -30,17 +30,29 @@ class AddParentField extends AbstractMigration
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public
function
change
()
public
function
up
()
{
$table
=
$this
->
table
(
'contreparties'
);
$table
->
addColumn
(
'parent'
,
'integer'
);
$table
->
update
();
if
(
!
$table
->
hasColumn
(
'parent'
))
{
$table
->
addColumn
(
'parent'
,
'integer'
);
$table
->
save
();
}
// Let's set some default value
$builder
=
$this
->
getQueryBuilder
();
$stmt
=
$builder
->
update
(
'contreparties'
)
$stmt
=
$builder
->
update
(
'contreparties'
,
'c'
)
->
set
(
'parent'
,
'id'
)
->
where
(
[
'parent
'
=
>
''
]
)
//
->where('parent =
0'
)
->
execute
();
}
public
function
down
()
{
$table
=
$this
->
table
(
'contreparties'
);
if
(
$table
->
hasColumn
(
'parent'
))
{
$table
->
removeColumn
(
'parent'
)
->
save
();
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment