init script to create an empty db
This commit is contained in:
		
							parent
							
								
									865472af51
								
							
						
					
					
						commit
						9352ca665d
					
				
					 1 changed files with 27 additions and 0 deletions
				
			
		
							
								
								
									
										27
									
								
								dbmigration/create_empty_db.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								dbmigration/create_empty_db.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,27 @@
 | 
				
			||||||
 | 
					#!/usr/bin/python
 | 
				
			||||||
 | 
					# -*- coding: UTF-8 -*-
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import sqlite3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					connection = sqlite3.connect("db.sqlite")
 | 
				
			||||||
 | 
					cursor = connection.cursor()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# What script performs: 
 | 
				
			||||||
 | 
					# - first, remove site table: crash here if table doesn't exist (compatibility test without effort)
 | 
				
			||||||
 | 
					# - remove site_id colum from comment table
 | 
				
			||||||
 | 
					script = """
 | 
				
			||||||
 | 
					CREATE TABLE comment (
 | 
				
			||||||
 | 
					    id INTEGER NOT NULL PRIMARY KEY, 
 | 
				
			||||||
 | 
						url VARCHAR(255) NOT NULL, 
 | 
				
			||||||
 | 
						notified DATETIME,
 | 
				
			||||||
 | 
						created DATETIME NOT NULL, 
 | 
				
			||||||
 | 
						published DATETIME, 
 | 
				
			||||||
 | 
						author_name VARCHAR(255) NOT NULL, 
 | 
				
			||||||
 | 
						author_site VARCHAR(255) NOT NULL,
 | 
				
			||||||
 | 
						author_gravatar varchar(255),
 | 
				
			||||||
 | 
						content TEXT NOT NULL 
 | 
				
			||||||
 | 
					, ulid INTEGER);
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cursor.executescript(script)
 | 
				
			||||||
 | 
					connection.close()
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue