2011-09-10 7 views
0

Codeigniter를 사용하여 자체 cms를 구축하려고합니다. 이미 일부 모듈을 작성했습니다. 그러나, 나는 그들과 약간의 변화를 만들었다. 모듈을 업그레이드하고 싶습니다. phpmyadmin으로 ftp로 파일을 보내고 데이터베이스 필드를 변경합니다.데이터베이스 프로세스를위한 Codeigniter 업그레이드 가능한 모듈 로직

변경할 시간이 많고 잘못 될 가능성이 높습니다.이 모듈을 사용한 모든 프로젝트에서이 변경 사항을 다시 반복해야합니다.

이제 설치 시스템을 만들 계획입니다.

내 모듈 디렉토리 구조 아래와 같이 :

/modules 
/modules/survey/ 
/modules/survey/config 
/modules/survey/config/autoload.php 
/modules/survey/config/config.php 
/modules/survey/config/routes.php 
/modules/survey/config/install.php 
/modules/survey/controllers 
/modules/survey/controllers/entry.php... 
/modules/survey/models 
/modules/survey/models/survey.php... 
/modules/survey/views 
/modules/survey/views/index.php... 

나는 모든 모듈이 config 디렉토리에 install.php 파일 파일을 가져야한다고 생각했다. 그것은 releated 모듈의 설정을 유지합니다. 아래처럼 : 내가 설치 스크립트를 만들려고 노력하고 있어요, 지금

id, module, module_slug, version 

:

$config['version'] = 1.1; //or 1.2, 1.3 etc. 
$config['module'] = 'Survey Module'; 
$config['module_slug'] = 'survey'; 
$config['module_db_table'] = 'module_survey'; 

나는 이미 installed_modules 테이블이있다. 아래처럼 :

시작하기 전에 모듈의 파일을 압축합니다.

1- upload zip file with an installation page to a temp directory 
2- unzip the module in this temp direcorty 
3- Find install.php 
4- Get modules information from install.php 
5- Check if this module already in installed_modules table. 
6a) If it's not: I will make a new module_survey table. And copy this temp directory into the real modules directory. 
6b) If it's already : I have to change the structure of this table without lossing the data added before. Delete all module files and copy the new ones from temp into the modules directory. 
7- When everything done, Delete temp directory. 

나는 6a와 6b에 찔 렸다.

6a의 경우 e.x 'module_survey'테이블을 어떻게 작성해야합니까? 은 내가

$config['db_query'] = "CREATE TABLE IF NOT EXISTS `module_survey` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`name` varchar(50) DEFAULT NULL, 
`lang_id` int(11) NOT NULL DEFAULT '1', 
`usort` int(3) DEFAULT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; 
"; 

같은 install.php 파일 달러 (A $)의 설정 [ 'db_query를'] 추가하고이 쿼리를 실행해야합니다. 아니면 여기서 당신의 충고는 무엇입니까? 테이블이 하나만있는 것은 아니며, 서로 다른 모듈에 대해 서로 관계가 있어야합니다.

및도 6b를 들어

:

내가, 내가 명 "temp_module_survey"와 같은 새로운 임시 테이블을 작성해야한다고 생각

.

이전 필드 =
$ oldFields = $ this-> db-> field_data ('module_survey');

새 필드 = $ newFields = $ this-> db-> field_data ('temp_module_survey');

은 새로 추가 된 필드와 삭제 된 fieldData가 변경된 필드를 비교합니다. 및 oldfield에 새 필드 추가 oldTable 에서 불필요한 필드를 삭제하고 fieldData가 변경된 필드를 업데이트하십시오.

그런 다음 임시 테이블을 제거하십시오.

요약하면 이전 데이터를 손실하지 않고 데이터베이스를 변경하려면 어떻게해야합니까?

나는 설명 할 수 있었으면 좋겠다.

감사합니다.

답변

관련 문제