Modifications entre les versions 4 et 13 (s'étendant sur 9 versions)
Version 4 à la date du 2013-08-29 16:32:17
Taille: 5312
Commentaire:
Version 13 à la date du 2013-09-06 13:09:42
Taille: 6026
Éditeur: DavinBaragiotta
Commentaire:
Texte supprimé. Texte ajouté.
Ligne 1: Ligne 1:
= Chargement de l'environnement virtuel = ## page was renamed from Projet/SemaineTech/2013/Ateliers/DjangoInspectdbSouth/support
= Django : SGBD inspectDb et South =

<<TableOfContents(3)>>

Légende: Les X-( sont les liens directs vers le code source, si vous voulez voir une solution qui marche

== Chargement de l'environnement virtuel ==
Ligne 4: Ligne 11:
([[/Projet/SemaineTech/2013/Ateliers/DjangoInspectdbSouth|Voir les prérequis de l'atelier]])
{{{ source atelier/bin/activtate }}}
([[Projet/SemaineTech/2013/Ateliers/DjangoInspectdbSouth|Voir les prérequis de l'atelier]])
Ligne 7: Ligne 13:
= Création d'un projet Django = {{{
source atelier/bin/activate
}}}

=
= Création d'un projet Django ==
Ligne 10: Ligne 20:
== Boostrap == === Boostrap ===
Ligne 13: Ligne 23:
python manage.py startproject foad django-admin.py startproject foad
Ligne 28: Ligne 38:
== Base de données MySQL == === Base de données MySQL ===
Ligne 39: Ligne 49:
== Activation de l'admin == === Activation de l'admin ===
Ligne 56: Ligne 66:
= Exploiter l'existant = == Exploiter l'existant ==
Ligne 63: Ligne 73:
== Câblage db == === Câblage db ===
Ligne 83: Ligne 93:
== Câblage de l'ancien dans l'admin == === Câblage de l'ancien dans l'admin ===
Ligne 86: Ligne 96:
Ligne 88: Ligne 99:
== Nouveau système ==
Ligne 89: Ligne 101:
= Nouveau système =

  *
{{ python manage.py startapp catalogue }}
{{{
python manage.py startapp catalogue
}}}
Ligne 95: Ligne 107:
== initialisation du framework de migration pour l'app == === initialisation du framework de migration pour l'app ===
Ligne 102: Ligne 114:
== Création du script de modification de BD selon le modèle ==
=== Création du script de modification de BD selon le modèle ===
Ligne 106: Ligne 117:
Ligne 116: Ligne 128:
== Itération 1 (création des formations à partir de l'existant) == === Itération 1 (création des formations à partir de l'existant) ===
Ligne 119: Ligne 131:
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/migrations/0003_recuperation_id_intitule.py#L9 ]]
Ligne 122: Ligne 133:
Itération 2 (création des universités à partir de l'existant)
------------------------------------------------------------
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/migrations/0003_recuperation_id_intitule.py#L9 ]]


=== Itération 2 (création des universités à partir de l'existant) ===
Ligne 125: Ligne 138:
* python manage.py schemamigration catalogue --auto
* python manage.py migrate catalogue
* python manage.py datamigration catalogue creation_universite --freeze ancien
* python manage.py migrate catalogue
{{{
python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue
}}}
{{{
python manage.py datamigration catalogue creation_universite --freeze ancien
}}}
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/cd81764142cce07ee2fb050e237a73f2815eb17c/catalogue/models.py]]
{{{
python manage.py migrate catalogue
}}}
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/migrations/0005_creation_universite.py#L9]]
Ligne 130: Ligne 151:
Itération 3 (création des domaines à partir de l'existant)
------------------------------------------------------------
=== Itération 3 (création des domaines à partir de l'existant) ===
Ligne 133: Ligne 153:
* python manage.py schemamigration catalogue --auto
* python manage.py migrate catalogue
* python manage.py datamigration catalogue creation_domaine --freeze ancien
* python manage.py migrate catalogue
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/models.py#L20]]
{{{
python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue
}}}
Ligne 138: Ligne 159:
Commandes utiles
----------------
{{{
python manage.py datamigration catalogue creation_domaine --freeze ancien
}}}
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/migrations/0007_creation_domaine.py#L9]]
{{{
python manage.py migrate catalogue
}}}

== Commandes utiles ==
Ligne 141: Ligne 170:
transactionnelle, il est bon re resetter l'application dans un état stable, transactionnelles, il est bon resetter l'application dans un état stable,
Ligne 144: Ligne 173:
* python manage.py sqlclear catalogue > del_catalogue
* mysql -u o -p --database=atelier < del_catalogue
* python manage.py dbshell
{{{
python manage.py sqlclear catalogue > del_catalogue
mysql -u <user> -p --database=atelier < del_catalogue
python manage.py dbshell
Ligne 148: Ligne 178:
}}}

Django : SGBD inspectDb et South

Légende: Les X-( sont les liens directs vers le code source, si vous voulez voir une solution qui marche

Chargement de l'environnement virtuel

(Voir les prérequis de l'atelier)

source atelier/bin/activate

Création d'un projet Django

Boostrap

django-admin.py startproject foad
cd foad
python manage.py runserver (CTRL+C)
echo "*.pyc" > .gitignore
git init
git add .
git commit -m 'nouveau projet'

{OK} à chaque modification correcte au cours de l'atelier, commiter-les, vous pourrez plus facilement voir les modifications de fichiers, revenir en arrière, etc...

Base de données MySQL

python manage.py syncdb

(créer le superuser)

Activation de l'admin

Exploiter l'existant

Création de l'application

django-admin.py startapp ancien

Câblage db

Câblage de l'ancien dans l'admin

Nouveau système

python manage.py startapp catalogue
  • dans 'foad/settings.py':
    • variable INSTALLED_APPS, ajouter votre nouvelle application: 'catalogue'

initialisation du framework de migration pour l'app

python manage.py schemamigration catalogue --initial
python manage.py migrate catalogue

Création du script de modification de BD selon le modèle

* création du modèle Formation dans catalogue/models.py

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/models.py

python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue

* création d'un fichier catalogue/admin.py X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/admin.py

Itération 1 (création des formations à partir de l'existant)

python manage.py datamigration catalogue recuperation_id_intitule  --freeze ancien

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/migrations/0003_recuperation_id_intitule.py#L9

Itération 2 (création des universités à partir de l'existant)

* ajout du modèle Universite dans catalogue/models.py

python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue

python manage.py datamigration catalogue creation_universite  --freeze ancien

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/cd81764142cce07ee2fb050e237a73f2815eb17c/catalogue/models.py

python manage.py migrate catalogue

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/migrations/0005_creation_universite.py#L9

Itération 3 (création des domaines à partir de l'existant)

* ajout du modèle Universite dans catalogue/models.py X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/models.py#L20

python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue

python manage.py datamigration catalogue creation_domaine  --freeze ancien

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/migrations/0007_creation_domaine.py#L9

python manage.py migrate catalogue

Commandes utiles

En cas, d'une migration échouée, comme les modifications ne sont pas transactionnelles, il est bon resetter l'application dans un état stable, corrélé avec les modèles.

python manage.py sqlclear catalogue > del_catalogue
mysql -u <user> -p --database=atelier < del_catalogue
python manage.py dbshell
  - delete from south_migrationhistory where app_name = 'catalogue';

Projet/SemaineTech/2013/Ateliers/DjangoInspectdbSouth/Support (dernière édition le 2013-09-06 13:09:42 par DavinBaragiotta)