Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
compendium-v2
Commits
6ccb6b99
Commit
6ccb6b99
authored
2 years ago
by
Remco Tukker
Browse files
Options
Downloads
Patches
Plain Diff
use int instead of bigint for the id column to make sqlite autoincrement work
parent
dd96c4d7
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1
normalization of nrens including datamigration
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
compendium_v2/db/model.py
+3
-3
3 additions, 3 deletions
compendium_v2/db/model.py
compendium_v2/migrations/versions/df2536b06f35_normalize_nrens.py
+3
-3
3 additions, 3 deletions
...um_v2/migrations/versions/df2536b06f35_normalize_nrens.py
test/conftest.py
+2
-2
2 additions, 2 deletions
test/conftest.py
with
8 additions
and
8 deletions
compendium_v2/db/model.py
+
3
−
3
View file @
6ccb6b99
...
@@ -25,13 +25,13 @@ base_schema: Any = declarative_base(metadata=metadata_obj)
...
@@ -25,13 +25,13 @@ base_schema: Any = declarative_base(metadata=metadata_obj)
class
NREN
(
base_schema
):
class
NREN
(
base_schema
):
__tablename__
=
'
nrens
'
__tablename__
=
'
nrens
'
id
=
sa
.
Column
(
sa
.
Big
Integer
,
primary_key
=
True
)
id
=
sa
.
Column
(
sa
.
Integer
,
primary_key
=
True
)
name
=
sa
.
Column
(
sa
.
String
(
128
),
nullable
=
False
)
name
=
sa
.
Column
(
sa
.
String
(
128
),
nullable
=
False
)
class
BudgetEntry
(
base_schema
):
class
BudgetEntry
(
base_schema
):
__tablename__
=
'
budgets
'
__tablename__
=
'
budgets
'
nren_id
=
sa
.
Column
(
sa
.
Big
Integer
,
sa
.
schema
.
ForeignKey
(
NREN
.
id
),
primary_key
=
True
)
nren_id
=
sa
.
Column
(
sa
.
Integer
,
sa
.
schema
.
ForeignKey
(
NREN
.
id
),
primary_key
=
True
)
nren
=
relationship
(
NREN
)
nren
=
relationship
(
NREN
)
year
=
sa
.
Column
(
sa
.
Integer
,
primary_key
=
True
)
year
=
sa
.
Column
(
sa
.
Integer
,
primary_key
=
True
)
budget
=
sa
.
Column
(
sa
.
Numeric
(
asdecimal
=
False
),
nullable
=
False
)
budget
=
sa
.
Column
(
sa
.
Numeric
(
asdecimal
=
False
),
nullable
=
False
)
...
@@ -39,7 +39,7 @@ class BudgetEntry(base_schema):
...
@@ -39,7 +39,7 @@ class BudgetEntry(base_schema):
class
FundingSource
(
base_schema
):
class
FundingSource
(
base_schema
):
__tablename__
=
'
funding_source
'
__tablename__
=
'
funding_source
'
nren_id
=
sa
.
Column
(
sa
.
Big
Integer
,
sa
.
schema
.
ForeignKey
(
NREN
.
id
),
primary_key
=
True
)
nren_id
=
sa
.
Column
(
sa
.
Integer
,
sa
.
schema
.
ForeignKey
(
NREN
.
id
),
primary_key
=
True
)
nren
=
relationship
(
NREN
)
nren
=
relationship
(
NREN
)
year
=
sa
.
Column
(
sa
.
Integer
,
primary_key
=
True
)
year
=
sa
.
Column
(
sa
.
Integer
,
primary_key
=
True
)
client_institutions
=
sa
.
Column
(
client_institutions
=
sa
.
Column
(
...
...
This diff is collapsed.
Click to expand it.
compendium_v2/migrations/versions/df2536b06f35_normalize_nrens.py
+
3
−
3
View file @
6ccb6b99
...
@@ -20,7 +20,7 @@ def upgrade():
...
@@ -20,7 +20,7 @@ def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
# ### commands auto generated by Alembic - please adjust! ###
op
.
create_table
(
op
.
create_table
(
'
nrens
'
,
'
nrens
'
,
sa
.
Column
(
'
id
'
,
sa
.
Big
Integer
(),
nullable
=
False
),
sa
.
Column
(
'
id
'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'
name
'
,
sa
.
String
(
length
=
128
),
nullable
=
False
),
sa
.
Column
(
'
name
'
,
sa
.
String
(
length
=
128
),
nullable
=
False
),
sa
.
PrimaryKeyConstraint
(
'
id
'
,
name
=
op
.
f
(
'
pk_nrens
'
))
sa
.
PrimaryKeyConstraint
(
'
id
'
,
name
=
op
.
f
(
'
pk_nrens
'
))
)
)
...
@@ -29,13 +29,13 @@ def upgrade():
...
@@ -29,13 +29,13 @@ def upgrade():
"
SELECT DISTINCT nren FROM budgets UNION SELECT DISTINCT nren FROM funding_source;
"
"
SELECT DISTINCT nren FROM budgets UNION SELECT DISTINCT nren FROM funding_source;
"
)
)
op
.
add_column
(
'
budgets
'
,
sa
.
Column
(
'
nren_id
'
,
sa
.
Big
Integer
()))
op
.
add_column
(
'
budgets
'
,
sa
.
Column
(
'
nren_id
'
,
sa
.
Integer
()))
op
.
execute
(
"
UPDATE budgets SET nren_id = nrens.id FROM nrens WHERE budgets.nren = nrens.name
"
)
op
.
execute
(
"
UPDATE budgets SET nren_id = nrens.id FROM nrens WHERE budgets.nren = nrens.name
"
)
op
.
alter_column
(
'
budgets
'
,
'
nren_id
'
,
nullable
=
False
)
op
.
alter_column
(
'
budgets
'
,
'
nren_id
'
,
nullable
=
False
)
op
.
create_foreign_key
(
op
.
f
(
'
fk_budgets_nren_id_nrens
'
),
'
budgets
'
,
'
nrens
'
,
[
'
nren_id
'
],
[
'
id
'
])
op
.
create_foreign_key
(
op
.
f
(
'
fk_budgets_nren_id_nrens
'
),
'
budgets
'
,
'
nrens
'
,
[
'
nren_id
'
],
[
'
id
'
])
op
.
drop_column
(
'
budgets
'
,
'
nren
'
)
op
.
drop_column
(
'
budgets
'
,
'
nren
'
)
op
.
add_column
(
'
funding_source
'
,
sa
.
Column
(
'
nren_id
'
,
sa
.
Big
Integer
()))
op
.
add_column
(
'
funding_source
'
,
sa
.
Column
(
'
nren_id
'
,
sa
.
Integer
()))
op
.
execute
(
"
UPDATE funding_source SET nren_id = nrens.id FROM nrens WHERE funding_source.nren = nrens.name
"
)
op
.
execute
(
"
UPDATE funding_source SET nren_id = nrens.id FROM nrens WHERE funding_source.nren = nrens.name
"
)
op
.
alter_column
(
'
funding_source
'
,
'
nren_id
'
,
nullable
=
False
)
op
.
alter_column
(
'
funding_source
'
,
'
nren_id
'
,
nullable
=
False
)
op
.
create_foreign_key
(
op
.
f
(
'
fk_funding_source_nren_id_nrens
'
),
'
funding_source
'
,
'
nrens
'
,
[
'
nren_id
'
],
[
'
id
'
])
op
.
create_foreign_key
(
op
.
f
(
'
fk_funding_source_nren_id_nrens
'
),
'
funding_source
'
,
'
nrens
'
,
[
'
nren_id
'
],
[
'
id
'
])
...
...
This diff is collapsed.
Click to expand it.
test/conftest.py
+
2
−
2
View file @
6ccb6b99
...
@@ -73,7 +73,7 @@ def test_budget_data():
...
@@ -73,7 +73,7 @@ def test_budget_data():
with
db
.
session_scope
()
as
session
:
with
db
.
session_scope
()
as
session
:
data
=
[
row
for
row
in
_test_data_csv
(
"
BudgetTestData.csv
"
)]
data
=
[
row
for
row
in
_test_data_csv
(
"
BudgetTestData.csv
"
)]
nren_names
=
set
([
row
[
"
nren
"
]
for
row
in
data
])
nren_names
=
set
([
row
[
"
nren
"
]
for
row
in
data
])
nren_dict
=
{
nren_name
:
model
.
NREN
(
id
=
idx
+
1
,
name
=
nren_name
)
for
idx
,
nren_name
in
enumerate
(
nren_names
)
}
nren_dict
=
{
nren_name
:
model
.
NREN
(
name
=
nren_name
)
for
nren_name
in
nren_names
}
session
.
add_all
(
nren_dict
.
values
())
session
.
add_all
(
nren_dict
.
values
())
for
row
in
data
:
for
row
in
data
:
...
@@ -121,7 +121,7 @@ def test_funding_source_data():
...
@@ -121,7 +121,7 @@ def test_funding_source_data():
with
db
.
session_scope
()
as
session
:
with
db
.
session_scope
()
as
session
:
data
=
[
row
for
row
in
_test_data_csv
(
"
FundingSourceTestData.csv
"
)]
data
=
[
row
for
row
in
_test_data_csv
(
"
FundingSourceTestData.csv
"
)]
nren_names
=
set
([
row
[
"
nren
"
]
for
row
in
data
])
nren_names
=
set
([
row
[
"
nren
"
]
for
row
in
data
])
nren_dict
=
{
nren_name
:
model
.
NREN
(
id
=
idx
+
1
,
name
=
nren_name
)
for
idx
,
nren_name
in
enumerate
(
nren_names
)
}
nren_dict
=
{
nren_name
:
model
.
NREN
(
name
=
nren_name
)
for
nren_name
in
nren_names
}
session
.
add_all
(
nren_dict
.
values
())
session
.
add_all
(
nren_dict
.
values
())
for
row
in
data
:
for
row
in
data
:
...
...
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