Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old databases migrations #1038

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

Old databases migrations #1038

wants to merge 24 commits into from

Conversation

vlejd
Copy link

@vlejd vlejd commented Apr 1, 2017

Migration scripts for kms, fks, ksp and some csv files.

We do not migrate old competitions nor old camps.

@vlejd vlejd requested review from mhozza, Zajozor and matejbadin April 1, 2017 12:52
@codecov
Copy link

codecov bot commented Apr 1, 2017

Codecov Report

Merging #1038 into master will decrease coverage by 3.13%.
The diff coverage is 4.27%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1038      +/-   ##
=========================================
- Coverage   70.13%     67%   -3.14%     
=========================================
  Files         107     112       +5     
  Lines        5126    5388     +262     
  Branches      672     707      +35     
=========================================
+ Hits         3595    3610      +15     
- Misses       1417    1664     +247     
  Partials      114     114
Impacted Files Coverage Δ
trojsten/people/helpers.py 95.91% <ø> (ø) ⬆️
...n/people/management/commands/migrate_ksp_kaspar.py 0% <0%> (ø)
...ple/management/commands/migrate_30rokovfks1_csv.py 0% <0%> (ø)
...ple/management/commands/migrate_30rokovfks2_csv.py 0% <0%> (ø)
...sten/people/management/commands/migrate_kms_csv.py 0% <0%> (ø)
...n/people/management/commands/migrate_base_class.py 0% <0%> (ø)
...sten/people/management/commands/migrate_fks_csv.py 0% <0%> (ø)
trojsten/people/constants.py 100% <100%> (ø) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db5808e...df2bdbd. Read the comment docs.

@mhozza
Copy link
Member

mhozza commented Apr 1, 2017

Preco su tam 2 fks migracne skripty? aky je medzi nimi rozdiel?

Predpokladam ze kedze to pouzijeme asi len raz, tak sa nam k tomu asi nechce pisat testy, ale v tom pripade si chceme byt isty ze to robi co ma a pouzit to skor ako to bude out of date.

btw treba to zrejme rebasnut.

@vlejd
Copy link
Author

vlejd commented Apr 2, 2017

Su tam 3 FKS skripty. Jeden je na staru databazu, a dva su na dva rvozne druhy CSV ciek z akcie 30 rokov fks.

Rad k tomu napisem nejake testy, len si niesom uplne isty ako. Mockovat vsetky tie databazy a subory by som nerad. Mozem ale napisat checker na niekolko userov a to, ako sa mali pomigrovat.

@vlejd vlejd requested a review from maaario June 17, 2017 21:09
@vlejd
Copy link
Author

vlejd commented Jun 17, 2017

@mhozza @maaario kukne sa mi na to uz niekto?

Copy link
Member

@mhozza mhozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry ze to tolko trvalo, ale tu mas.
Zatial som pozerak ksp a base.
Skus aplikovat pripomienky aj na ostatne veci, potom to pozriem cele.

BIRTHDAY_PROP = 2


class Command(MigrateBaceCommand):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base

for row in c:
self.process_school(*row)

# TODO sustredka
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mozno by bolo dobre tuna linknut issue na githube, aby to nebol len nahodny comment v kode, na ktory sa zabudne.

class Command(MigrateBaceCommand):
help = 'Imports people and their related info from kaspar.'

def handle_noargs(self, **options):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tato metoda toho robi uz prilis vela, treba to rozdelit do mensich metod.

  • ziskanie zoznamu sustrediek
  • ziskanie zoznamu ucastnikov
  • ziskanie poctu sustredeni

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

sys.setdefaultencoding("utf-8")


class MigrateBaceCommand(NoArgsCommand):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

dest='dry',
default=True,
help='Actually write something to DB')
parser.add_argument('--fast',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toto chce lepsi description - co je to "few users"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if self.dry:
new_user = User(**user_args)
else:
addr = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naco je tu tato premenna - ak dobre vidim, addr sa pouzije len na riadku 197 a medzitym je aj tak prepisana.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

address['town'],
address['postal_code'],
address['country'])
user_args['home_address'] = addr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu mozes rovno priradit to co priradujes do addr a addr vyhodit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if valid_contacts:
user_properties.append([self.LAST_CONTACT_PROPERTY, max(valid_contacts)])

user_properties = list(filter(lambda x: x, user_properties))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toto je velmi obskurne. Co napriklad:
user_properties = [prop for prop in user_properties if prop is not None]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


similar_users = get_similar_users(new_user)
if len(similar_users):
names_of_similar = [(x.first_name, x.last_name) for x in similar_users]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nie som uplne fanusik pouzivania premennej x na vsetko ale whatever.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

self.similar_users.append(((first_name, last_name), names_of_similar))
if self.verbosity >= 2:
self.stdout.write('Similar users: %s' % str(names_of_similar))
if self.dry:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

co napr. if not self.dry:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@matejbadin
Copy link
Contributor

@vlejd @mhozza Ahojte, v akom je toto momentálne stave?

@mhozza
Copy link
Member

mhozza commented Aug 16, 2017

Pokial mi je zname, od mojho podledneho review sa nic neudialo (Vlejd tusim pise diplomovku alebo co)

@vlejd
Copy link
Author

vlejd commented Aug 21, 2017

Momentalny stav je, ze si vybavujem povolenie v googli, aby som mohol nico urobit. Ono google ma narok na vsetok kod ktory napises ked si tam zamestnany a mohli by z toho byt problemy.

@mhozza
Copy link
Member

mhozza commented Aug 21, 2017 via email

@@ -120,7 +121,8 @@ def create_school(self, abbr, name, addr_name, street,
abbr += '?' # Question mark denotes schools needing review.
school = None
if len(zip_code) > 10:
# Swiss zip codes
# Swiss zip codes are longer than 10 chars, but our db model does not allow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nechceme zmenit model aby ich podporoval?
Ak sa nam nechce teraz, mozes sem pridat TODO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ake dlhe su svajciarske PSC? Podla wikipedia a google map 4 miesta.

trojsten/people/management/commands/migrate_base_class.py Outdated Show resolved Hide resolved
@black3r
Copy link
Member

black3r commented Mar 11, 2018

V python 3 nefunguje, skonci s chybou AttributeError: module 'sys' has no attribute 'setdefaultencoding'

@black3r
Copy link
Member

black3r commented Mar 11, 2018

Po lokálnom spustení s python2
python manage.py migrate_fks_csv data/csv/fks/ --wet_run skonci s chybou

Traceback (most recent call last):
  File "manage.py", line 40, in <module>
    execute_from_command_line(sys.argv)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/roman/work/trojsten/web/trojsten/people/management/commands/migrate_fks_csv.py", line 100, in handle
    address=parsed_address)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner
    return func(*args, **kwargs)
  File "/home/roman/work/trojsten/web/trojsten/people/management/commands/migrate_base_class.py", line 200, in process_person
    postal_code=address['postal_code'], country=address['country'])
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/query.py", line 394, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/base.py", line 808, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/base.py", line 838, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/base.py", line 924, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/base.py", line 963, in _do_insert
    using=using, raw=raw)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/query.py", line 1076, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1112, in execute_sql
    cursor.execute(sql, params)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/roman/.pyenv/versions/trojsten-2/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(2)

@mhozza
Copy link
Member

mhozza commented Jul 9, 2019

Uz by to malo bezat pod py3.
@black3r Ako si to skusal lokalne? odkial mas data na migraciu?

@mhozza mhozza requested a review from black3r July 14, 2019 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants