NetAngelsã§ã»ãšãã©ã®æéãè²»ãããŠãããã¹ãã£ã³ã°ã³ã³ãããŒã«ããã«ã®ãããžã§ã¯ãã§ã¯ããã¹ãäžã«120åã®ããŒãã«ãšãã£ã¯ã¹ãã£ããã®çŽ500åã®ãªããžã§ã¯ããããŒããããŸãã ããã¯æãããã»ã©å€ãã¯èšããŸãããããã¹ãŠã®ããŒãã«ãäœæãããã¹ããå®è¡ãããã³ã«ã€ã³ããã¯ã¹ãè¿œå ãããªããžã§ã¯ããããŒãããããšã¯ãç¹ã«1ã€ãŸãã¯2ã€ã ãã®ãã¹ããå®è¡ããå Žåã¯éåžžã«é¢åã§ãã
ç«ã®äžã§ã¯ã以åã«ææ¡ããããã¹ããé«éåããããã®ããã€ãã®æ¹æ³ãããç°¡æœã«ãªã¹ããããŠãããæåŸã«å¥ã®æçšãªã¬ã·ãã®è©³çŽ°ãªèª¬æããããŸãããç§ã¯ä»ããã¹ãå®è¡ã®é床ã®åé¡ããã§ã«å®å šã«é€å»ããŠããããšãé¡ã£ãŠããŸãã
å¹³åçãªã¢ããªã±ãŒã·ã§ã³ã§ã¯ãååãšããŠãã»ãšãã©ã®ãã¬ãŒãã¯ããŒã¿ããŒã¹ã®æäœã«é¢é£ä»ããããŸãã ã»ãšãã©ãã¹ãŠã®ææ¡ããã®ç¹å®ã®ã³ã³ããŒãã³ãã®æé©åãç®çãšããŠããããšã¯é©ãããšã§ã¯ãããŸããã
次ã«ãããŒã¿ããŒã¹ã®æäœã¯äž»ã«ãã£ã¹ã¯ãµãã·ã¹ãã ã«ãã£ãŠé ããªããŸãããã®è² è·ãäœããã®æ¹æ³ã§åæžãããšãããã©ãŒãã³ã¹ãå€§å¹ ã«åäžãããšæ³å®ããã®ã¯çã«ããªã£ãŠããŸãã
å®å šã§ãªããã©ã³ã¶ã¯ã·ã§ã³èšå®
ãã¹ãããã»ã¹äžã«é»æ°ãçªç¶å€±ãããããŒã¿ããã£ã¹ã¯ã«å®å šã«æžã蟌ãŸããªãå Žåã誰ãæ°ã«ããŸããã éåžžãããŒã¿ããŒã¹ãµãŒããŒã¯ããã®ãããªã€ãã³ãã®æ²ããçµæãæå°éã«æããããã«æ§æãããŠããŸãã ãã¹ãçšã«å¥ã®MySQLãµãŒããŒãŸãã¯PostgreSQLãµãŒããŒã䜿çšããå Žåãèšå®ãå®å šã«å®å šã«å€æŽã§ããŸãã
ç¹ã«ãMySQLã®å Žåã以äžãæäŸããŸãã
[mysqld]
default-table-type=innodb
transaction-isolation=READ-COMMITTED
innodb_flush_log_at_trx_commit = 0
skip-sync-frm=OFF
PostgreSQLã§ã¯ãåãç®çã§postgresql.confã«
fsync = off
ãªãã·ã§ã³ãè¿œå ããããšããå§ã
fsync = off
ãŸãã
ramdiskã䜿çšãã
ããæ ¹æ¬çãªã¢ãããŒãã¯ããã£ã¹ã¯ããŸã£ãã䜿çšããã代ããã«RAMå ã®ããŒã¿ãæäœããããšã§ãã äžè¬çãªååã¯ãtmpfsãã¡ã€ã«ã·ã¹ãã ã䜿çšããŠæ°ããããŒãã£ã·ã§ã³ãäœæããå¥ã®ãã£ã¬ã¯ããªã«ããŠã³ãããŠããããã¹ãŠã®ããŒã¿ããŒã¹ãã¡ã€ã«ããã®ãã£ã¬ã¯ããªã«äœæããããšã§ãã è¿œå ã®ããŒãã¹ã¯ãåã«ããŒãã£ã·ã§ã³ãã¢ã³ããŠã³ããããšãã¹ãŠã®ããŒã¿ãåé€ãããããšã§ãã
ãã¹ãçšã®SQLite
å®éãDjangoéçºè ã¯ããã¹ããã§ããã ãæ©ãå®è¡ããããã«å€ãã®ããšããã§ã«è¡ã£ãŠããŸãã ç¹ã«ãSQLiteãããŒã¿ããŒã¹ãšã³ãžã³ãšããŠäœ¿çšããå Žåããã¹ãäžã«ããŒã¿ããŒã¹ãã¡ã¢ãªã«äœæããïŒæåå "ïŒmemoryïŒ"ããã¡ã€ã«åãšããŠãã©ã€ãã«æž¡ãããŸãïŒããã®æ¹æ³ã ãã§ã»ãšãã©ã®åé¡ãé«éã§è§£æ±ºã§ããŸãã
ORM DjangoãããŒã¿ããŒã¹ã®è©³çŽ°ãæ éã«é ããŠããªããšäžå¹³ãèšãããšããããããå Žåã«ãã£ãŠã¯ãSQLiteã§æ©èœããã³ãŒãïŒã€ãŸãããã¹ãã«åæ Œããã³ãŒãïŒãããããååšããã·ã¹ãã ã«ããŒã«ã¢ãŠããããšçªç¶å£ããããšããããŸãMySQLã¯åäœããŸãã å®éãããã¯æã èµ·ãããŸãããååãšããŠãããªããäœããç°åžžãªãããšããããšããäºå®ã®çµæã§ããäŸãã°ãQuerySet.extraã¡ãœããã䜿çšããŠæåã§ã¯ãšãªãäœæãå§ããŸããã ãã ããã»ãšãã©ã®å Žåããã®ãããªããšãããã°ããããã©ã®ããã«è åšã«ãªãããç¥ã£ãŠããŸãã
äºåã®SQLiteãã¹ãããŒã¹ã®äœæ
ãåç¥ã®ããã«ããã¹ããå®è¡ãããšãDjangoã¯æ¬¡ã®äžé£ã®ã¢ã¯ã·ã§ã³ãå®è¡ããŸãã
1.ãŠãŒã¶ãŒã®èš±å¯ãåŸãŠããã¹ãããŒã¿ããŒã¹ãã¯ãªã¢ããŸãïŒãã¹ãããŒã¿ããŒã¹ã«äœããããå ŽåïŒ
2.ãã¹ãããŒã¿ããŒã¹ã«ãã¹ãŠã®ããŒãã«ãšã€ã³ããã¯ã¹ãäœæããŸã
3. initial_dataãšããäžé£ã®ãã£ã¯ã¹ãã£ãããŒãããŸã
4.ãã¹ãã1ã€ãã€å®è¡ããŸã
5.ãã¹ãäžã«äœæããããã¹ãŠãåé€ããŸã
ããŒã¿ãã¡ã¢ãªå ã«ååšããå ŽåãæåãšæåŸã®ã¹ããŒãžã¯å®è¡ãããªãå¯èœæ§ããããŸãããã¹ããã2ãš3ã«ã¯ããªãã®æéããããããã³ãŒããä¿®æ£ããŠãã¹ããéå§ããšããé«éã®å埩ãé ããªããŸãã æããã«ãããŒã¿ããŒã¹ã¹ããŒããšãã£ã¯ã¹ãã£ã»ããã¯ãã³ãŒããšãã¹ããããã¯ããã«å°ãªãé »åºŠã§å€æŽããããããããŒã¿ããŒã¹ã®çµ¶ãéãªãäœæãç¯çŽããããšã«ã¯æå³ããããŸãã ã¡ãªã¿ã«ãã¹ããã2ãš3ã¯ãsyncdb管çã³ãã³ãã®éåžžã®å®è¡ã§ãã
ãã¹ãã®å®è¡ãé«éåããäžè¬çãªã¢ãããŒãã¯ãsyncdbãæåã§å®è¡ããããšã§ããæ¬åœã«å¿ èŠãªå Žåã«ã®ã¿ããã¹ããéå§ãããšãã«æºåæžã¿ã®ããŒã¿ããŒã¹ãã³ããŒããã ãã§ãã SQLiteã䜿çšãããšããã¡ã€ã«ãã³ããŒããã«å®è¡ã§ããŸããããïŒmemoryïŒãã§ãã¹ããæäœããå©ç¹ã倱ããããããŸããã§ããã
çãæ€çŽ¢ã«ããããã®ã±ãŒã¹ã®è§£æ±ºçãååšããããšã瀺ãããŸããã SQLiteã«ã¯ãããããããã¯ã¢ããçšã®ã€ã³ã¿ãŒãã§ã€ã¹ãããïŒå€§äººã®å Žåãšåæ§ïŒãäºåã«æºåãããããŒã¿ããŒã¹ãããã®ãããªã³ããŒãååãmemoryã®ããŒã¿ããŒã¹ã«å®è¡ãããšããŸãã«å¿ èŠãªãã®ãåŸãããŸãïŒåæåãããããŒã¿ããŒã¹ã¡ã¢ãªå ã®ããŒã¿ã
å®è£ ã®æåã®é£ããã¯ãæšæºã®Pythonã¢ãžã¥ãŒã«sqlite3ããµããŒãããŠãããããããããã®APIããµããŒãããªãããšã§ãããããã£ãŠãPythonã䜿çšããŠãã®ãããªã³ããŒãå®è¡ããã«ã¯ãAPSWïŒAnother Python SQLite WrapperïŒãšãããµãŒãããŒãã£ã¢ãžã¥ãŒã«ã䜿çšããããšããå§ãããŸãã
2çªç®ã®é£ç¹ã¯ãã¡ã¢ãªå ã®æ°ããããŒã¿ããŒã¹æ¥ç¶ããšã«ãããŒã¿ããŒã¹ã®ç¬èªã®ã³ããŒïŒæããã«ç©ºïŒãäœæãããããORSWã䜿çšããã«ãŒãœã«ã«APSWã«ãã£ãŠåæåãããæ¥ç¶ã䜿çšããæ¹æ³ãæããå¿ èŠãããããšã§ãã 幞ããªããšã«ããã®å Žåã«ã¯ããã¯ãæäŸãããŸããsqlite3ã䜿çšããŠæ¥ç¶ãäœæãããšãã«ããã¡ã€ã«åã®ããè¡ã®ä»£ããã«ãapsw.Connectionãªããžã§ã¯ããæž¡ãããšãã§ããŸãã
ãã®ããããœãªã¥ãŒã·ã§ã³ã¯éåžžã«ã·ã³ãã«ã«èŠããŸãã
1. 2ã€ã®ASPWæ¥ç¶ãªããžã§ã¯ããäœæããŸãã1ã€ã¯äºåã«æºåãããããŒã¿ããŒã¹ãåç §ãããã1ã€ã¯ã¡ã¢ãªå ã®ããŒã¿ããŒã¹ãåç §ããŸãã
2.ãã¡ã€ã«ããã¡ã¢ãªã«ããŒã¿ãã³ããŒããŸãã
3.ãdefaultããšããååã®ãšã€ãªã¢ã¹ã®NAMEãã©ã¡ãŒã¿ãŒã«ã¯ãã¡ã¢ãªãåç §ããASPWæ¥ç¶ãæž¡ããŸãã
4.ã«ãŒãœã«ãåæåãããã¹ããå®è¡ããŸãã
ããŒã¿ããŒã¹ã®äœæã¯éåžžã«ç°¡åã§ãããquickstartããšããååã®ãšã€ãªã¢ã¹ãDATABASES settings.pyå€æ°ã«è¿œå ããŠããã.
./manage.py syncdb --database quickstart
å®è¡ãã
./manage.py syncdb --database quickstart
ã§ãã
ãããã®ã¢ã¯ã·ã§ã³ãå®è¡ã§ãããã¹ãŠã®ã³ãŒãã¯ã20è¡åŒ±ãããã以äžã«ç€ºããŸãã åäœãããã«ã¯ååã§ã
1. APSWãã€ã³ã¹ããŒã«ããŸã
2.ã³ãŒããå¥ã®ãã¡ã€ã«ã«ã³ããŒããŠããããžã§ã¯ãã«é 眮ããŸã
3. quickstartãšããååã®ããŒã¿ããŒã¹ã®settings.DABABASESã«ãšã€ãªã¢ã¹ãè¿œå ããŸã
4.
./manage.py syncdb --database quickstart
å®è¡ããŠããŒã¿ããŒã¹ãäœæããŸã
5.å€æ°TEST_RUNNERãèšå®ããŠãä¿åããã°ããã®ãªããžã§ã¯ãã®ã¯ã©ã¹ãåç §ããããã«ããŸã
6.ç°¡åãªãã¹ããå®è¡ããŠã¿ãŠãã ããã
Copy Source | Copy HTML
- ã€ã³ããŒã apsw
- ãžã£ã³ãŽãã ã ãã¹ã .simple import DjangoTestSuiteRunner
- django.db ã€ã³ããŒãæ¥ç¶ãã
- ã¯ã©ã¹ TestSuiteRunner ïŒDjangoTestSuiteRunnerïŒïŒ
- def setup_databases ïŒselfã** kwargsïŒïŒ
- quickstart_connection = connections [ 'quickstart' ]
- quickstart_dbname = quickstart_connection.settings_dict [ 'NAME' ]
- memory_connection = apsw.ConnectionïŒ 'ïŒã¡ã¢ãªïŒ' ïŒ
- quickstart_connection = apsw.ConnectionïŒquickstart_dbnameïŒ
- ããã¯ã¢ãããšã㊠memory_connection.backupïŒ 'main' ãquickstart_connectionã 'main' ïŒ ã䜿çšããŸãã
- backup.doneã§ã¯ãªãå ŽåïŒ
- backup.stepïŒ 100 ïŒ
- connection = connections [ 'default' ]
- connection.settings_dict [ 'NAME' ] = memory_connection
- ã«ãŒãœã«= connection.cursorïŒïŒ
- def teardown_databases ïŒselfãold_configã** kwargsïŒïŒ
- åæ Œãã
ãã®çµæã1ã€ã®ãã¹ãã®å®è¡æéã18ç§ãã2ç§ã«ççž®ãããŸãããå¿ èŠãªåæ°ã ããã¹ããå®è¡ããã®ã¯éåžžã«å¿«é©ã§ãã
åãã³ãŒãã§ãããã³ã¡ã³ããšããã¹ãã§ããŒã¿ãé£ã¹ãããå¯èœæ§ããããŸãïŒãïŒãã¹ãç°å¢ã§ã®ã¿äœ¿çšïŒãšãã倧èãªèŠåãgist.github.com/1044215ã§å©çšå¯èœã§ãã
ãããã®ç°¡åãªæšå¥šäºé ã«ãããã³ãŒããããéããããå¹ççã«ããã確å®ã«æžãããšãã§ããã°ãšæããŸãã
䜿çšãããœãŒã¹
詳现ããã³ãã®ä»ã®æçšãªæ å ±ã«ã€ããŠã¯ãããŒã¿ããŒã¹ãµãŒããŒã®ããã¥ã¡ã³ããšæ¬¡ã®ãœãŒã¹ãåç §ããããšããå§ãããŸãã
-MySQLã䜿çšããDjangoãŠããããã¹ãã®å®è¡ã®é«éå
-Innodbããã©ãŒãã³ã¹æé©åã®åºæ¬
-SQLite Online Backup APIã®äœ¿çš
-Pythonã§SQLiteã®ããã¯ã¢ããã䜿çšããæ¹æ³