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

Issue 33 #46

Merged
merged 2 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@

public/sitemap.xml
public/system/
doc/custom/extract_db_insert_*.sql
36 changes: 22 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,39 @@ cd consul
bundle install
cp config/database.yml.example config/database.yml
cp config/secrets.yml.example config/secrets.yml
bin/rake db:create
bin/rake db:migrate
bin/rake db:seed
bin/rake db:custom_seed
```

En production penser à bloquer l'accès aux comptes admin et verified.
Puis 2 options :

Certaines releases nécessitent des actions particulières suite à une montée de version.
Ces actions sont documentées dans [les releases](https://github.com/consul/consul/releases).
### Déployer avec import de la BDD originelle :

Récupérer une copie de la base de donnée à importer (dossier CDJ11_OSP) et la copier dans `doc/custom`.

Personnaliser si nécessaire le script `/lib/custom/import_db.sh`, ligne 4 :

psql NOM_BASE_DESTINATION < doc/custom/NOM_FICHIER_A_IMPORTER.sql

## Déploiement avec import
```bash
chmod 755 lib/custom/import_db.sh #si fichier non executable
./lib/custom/import_db.sh
```

L'import comprend déjà les geozones et les settings de base. Les geozones ne sont donc pas à importer (provoque une erreur).
Le script peut renvoyer un message d'erreur en fin de parcours (`duplicate key` lors de la creation d'un utilisateur admin), qui logiquement n'empêche pas la bonne exécution de l'intégralité du script.

Si une première version a déjà été déployée, il faut vider la base et la recréer vide pour effectuer l'import.
### Déployer sans import de la BDD originelle :

```bash
bin/rake db:drop
```
bin/rake db:create
bin/rake db:migrate
# suivant nom de la base sur l environnement a deployer
psql consul < doc/custom/extract_db_insert_180326.sql
bin/rake db:seed
bin/rake db:custom_seed
```

En production penser à bloquer l'accès aux comptes admin et verified.

Certaines releases nécessitent des actions particulières suite à une montée de version.
Ces actions sont documentées dans [les releases](https://github.com/consul/consul/releases).

## Configuration for development and test environments

**NOTE**: For more detailed instructions check the [docs](https://github.com/consul/docs/tree/master/en/getting_started/prerequisites)
Expand Down
2 changes: 1 addition & 1 deletion db/custom_seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def log(msg)

require_relative 'custom_seeds/settings'
require_relative 'custom_seeds/geozones'
# require_relative 'custom_seeds/users'
require_relative 'custom_seeds/users'
# require_relative 'custom_seeds/tags_categories'
# require_relative 'custom_seeds/debates'
# require_relative 'custom_seeds/proposals'
Expand Down
2 changes: 0 additions & 2 deletions db/custom_seeds/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
#Setting.create(key: 'max_ratio_anon_votes_on_debates', value: '50')
#Setting.create(key: 'max_votes_for_debate_edit', value: '1000')
#Setting.create(key: 'max_votes_for_proposal_edit', value: '1000')
#Setting.create(key: 'proposal_code_prefix', value: 'MAD')
#Setting.create(key: 'votes_for_proposal_success', value: '100')
#Setting.create(key: 'months_to_archive_proposals', value: '12')
#Setting.create(key: 'comments_body_max_length', value: '1000')

Expand Down
30 changes: 30 additions & 0 deletions db/custom_seeds/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
section "Creating Users" do

def unique_document_number
@document_number ||= 12345678
@document_number += 1
"#{@document_number}#{[*'A'..'Z'].sample}"
end

admin = User.where(email: '[email protected]').first_or_create!(
username: 'admin happy dev',
password: '12345678',
password_confirmation: '12345678',
confirmed_at: Time.current,
terms_of_service: "1",
gender: ['Male', 'Female'].sample,
date_of_birth: rand((Time.current - 80.years)..(Time.current - 16.years)),
public_activity: (rand(1..100) > 30),
residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number,
document_type: "1",
verified_at: Time.current,
document_number: unique_document_number
)
# TODO : following instruction genereate en error :
# `PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "administrators_pkey"
# DETAIL: Key (id)=(2) already exists.`
# Already too much time spent trying to debug it. It seems to work, anyway. Further check required later
admin.create_administrator unless admin.administrator.present?

end
Empty file added doc/custom/.keep
Empty file.
2,580 changes: 0 additions & 2,580 deletions doc/custom/extract_db_insert_180326.sql

This file was deleted.

8 changes: 8 additions & 0 deletions lib/custom/import_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bin/rake db:drop
bin/rake db:create
bin/rake db:migrate VERSION=20170513110025
psql cdj_development < doc/custom/extract_db_insert_180326.sql
bin/rake db:migrate
bin/rake db:seed
bin/rake db:custom_seed
bin/rake custom:finalize_db_import
17 changes: 17 additions & 0 deletions lib/custom/post_db_import.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Script permettant de gerer les liens et elements manquant apres l'import de la BDD originelle
module PostDbImport

def self.call!
set_proposals_community!
end

private

def self.set_proposals_community!
Proposal.where(community_id: nil).each do |proposal|
proposal.associate_community
proposal.save!
end
end

end
17 changes: 17 additions & 0 deletions lib/tasks/custom.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'custom/post_db_import'

namespace :custom do

desc "Finalise l'import de la BDD originelle"
task :finalize_db_import => :environment do |t, args|
p "==== finalize_db_import started: #{Time.now} ===="
begin
PostDbImport.call!
p "==== finalize_db_import ended: #{Time.now} ===="
rescue Exception => e
error = "Error: #{e}"
p error
end
end

end