Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
4f927721
Unverified
Commit
4f927721
authored
4 years ago
by
Julius Härtl
Browse files
Options
Downloads
Patches
Plain Diff
Add temporary test for migrating int to string
Signed-off-by:
Julius Härtl
<
jus@bitgrid.net
>
parent
aefe8262
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/lib/DB/MigratorTest.php
+49
-0
49 additions, 0 deletions
tests/lib/DB/MigratorTest.php
with
49 additions
and
0 deletions
tests/lib/DB/MigratorTest.php
+
49
−
0
View file @
4f927721
...
@@ -13,6 +13,7 @@ use Doctrine\DBAL\DBALException;
...
@@ -13,6 +13,7 @@ use Doctrine\DBAL\DBALException;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\SchemaConfig
;
use
Doctrine\DBAL\Schema\SchemaConfig
;
use
OC\DB\SchemaWrapper
;
use
OCP\IConfig
;
use
OCP\IConfig
;
/**
/**
...
@@ -94,6 +95,26 @@ class MigratorTest extends \Test\TestCase {
...
@@ -94,6 +95,26 @@ class MigratorTest extends \Test\TestCase {
return
[
$startSchema
,
$endSchema
];
return
[
$startSchema
,
$endSchema
];
}
}
/**
* @return \Doctrine\DBAL\Schema\Schema[]
*/
private
function
getChangedTypeSchema
(
$from
,
$to
)
{
$startSchema
=
new
Schema
([],
[],
$this
->
getSchemaConfig
());
$table
=
$startSchema
->
createTable
(
$this
->
tableName
);
$table
->
addColumn
(
'id'
,
$from
);
$table
->
addColumn
(
'name'
,
'string'
);
$table
->
addIndex
([
'id'
],
$this
->
tableName
.
'_id'
);
$endSchema
=
new
Schema
([],
[],
$this
->
getSchemaConfig
());
$table
=
$endSchema
->
createTable
(
$this
->
tableName
);
$table
->
addColumn
(
'id'
,
$to
);
$table
->
addColumn
(
'name'
,
'string'
);
$table
->
addIndex
([
'id'
],
$this
->
tableName
.
'_id'
);
return
[
$startSchema
,
$endSchema
];
}
private
function
getSchemaConfig
()
{
private
function
getSchemaConfig
()
{
$config
=
new
SchemaConfig
();
$config
=
new
SchemaConfig
();
$config
->
setName
(
$this
->
connection
->
getDatabase
());
$config
->
setName
(
$this
->
connection
->
getDatabase
());
...
@@ -123,6 +144,34 @@ class MigratorTest extends \Test\TestCase {
...
@@ -123,6 +144,34 @@ class MigratorTest extends \Test\TestCase {
$this
->
fail
(
'checkMigrate should have failed'
);
$this
->
fail
(
'checkMigrate should have failed'
);
}
}
public
function
testChangeToString
()
{
list
(
$startSchema
,
$endSchema
)
=
$this
->
getChangedTypeSchema
(
'integer'
,
'string'
);
$migrator
=
$this
->
manager
->
getMigrator
();
$migrator
->
migrate
(
$startSchema
);
$schema
=
new
SchemaWrapper
(
$this
->
connection
);
$table
=
$schema
->
getTable
(
substr
(
$this
->
tableName
,
3
));
$this
->
assertEquals
(
'integer'
,
$table
->
getColumn
(
'id'
)
->
getType
()
->
getName
());
$this
->
connection
->
insert
(
$this
->
tableName
,
[
'id'
=>
1
,
'name'
=>
'foo'
]);
$this
->
connection
->
insert
(
$this
->
tableName
,
[
'id'
=>
2
,
'name'
=>
'bar'
]);
$this
->
connection
->
insert
(
$this
->
tableName
,
[
'id'
=>
3
,
'name'
=>
'qwerty'
]);
$migrator
->
checkMigrate
(
$endSchema
);
$migrator
->
migrate
(
$endSchema
);
$this
->
addToAssertionCount
(
1
);
$qb
=
$this
->
connection
->
getQueryBuilder
();
$result
=
$qb
->
select
(
'*'
)
->
from
(
substr
(
$this
->
tableName
,
3
))
->
execute
();
$this
->
assertEquals
([
[
'id'
=>
1
,
'name'
=>
'foo'
],
[
'id'
=>
2
,
'name'
=>
'bar'
],
[
'id'
=>
3
,
'name'
=>
'qwerty'
]
],
$result
->
fetchAll
());
$schema
=
new
SchemaWrapper
(
$this
->
connection
);
$table
=
$schema
->
getTable
(
substr
(
$this
->
tableName
,
3
));
$this
->
assertEquals
(
'string'
,
$table
->
getColumn
(
'id'
)
->
getType
()
->
getName
());
}
public
function
testUpgrade
()
{
public
function
testUpgrade
()
{
list
(
$startSchema
,
$endSchema
)
=
$this
->
getDuplicateKeySchemas
();
list
(
$startSchema
,
$endSchema
)
=
$this
->
getDuplicateKeySchemas
();
$migrator
=
$this
->
manager
->
getMigrator
();
$migrator
=
$this
->
manager
->
getMigrator
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment