class SiSU_DbCreate::Create
Public Class Methods
new(opt,conn,file,sql_type=:pg)
click to toggle source
# File lib/sisu/db_create.rb, line 60 def initialize(opt,conn,file,sql_type=:pg) @opt,@conn,@file,@sql_type=opt,conn,file,sql_type @cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX @comment=(@sql_type==:pg) \ ? (SiSU_DbCreate::Comment.new(@conn,@sql_type)) : nil @@dl ||=SiSU_Env::InfoEnv.new.digest.length end
Public Instance Methods
available()
click to toggle source
# File lib/sisu/db_create.rb, line 68 def available DBI.available_drivers.each do |driver| puts "Driver: #{driver}" DBI.data_sources(driver).each do |dsn| puts "\tDatasource: #{dsn}" end end end
conn_exec(sql)
click to toggle source
# File lib/sisu/db_create.rb, line 103 def conn_exec(sql) if @sql_type==:pg conn_exec_pg(sql) elsif @sql_type==:sqlite conn_exec_sqlite(sql) end end
conn_exec_pg(sql)
click to toggle source
# File lib/sisu/db_create.rb, line 110 def conn_exec_pg(sql) begin @conn.exec_params(sql) rescue if @conn.is_a?(NilClass) errmsg="No pg connection (check pg dependencies)" if @opt.act[:no_stop][:set]==:on SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, proceeding without pg output (as requested)") else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, STOPPING") exit end end end end
conn_exec_sqlite(sql)
click to toggle source
# File lib/sisu/db_create.rb, line 127 def conn_exec_sqlite(sql) begin @conn.execute(sql) rescue if @conn.is_a?(NilClass) errmsg="No sqlite3 connection (check sqlite3 dependencies)" if @opt.act[:no_stop][:set]==:on SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, proceeding without sqlite output (as requested)") else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, STOPPING") exit end end end end
create_db()
click to toggle source
# File lib/sisu/db_create.rb, line 76 def create_db @env=SiSU_Env::InfoEnv.new(@opt.fns) tell=(@sql_type==:sqlite) \ ? SiSU_Screen::Ansi.new( @opt.act[:color_state][:set], 'Create SQLite db tables in:', %{"#{@file}"} ) : SiSU_Screen::Ansi.new( @opt.act[:color_state][:set], 'Create pgSQL db tables in:', %{"#{Db[:name_prefix]}#{@env.path.base_markup_dir_stub}"} ) if (@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) tell.dark_grey_title_hi end SiSU_Env::SystemCall.new.create_pg_db(@env.path.base_markup_dir_stub) if @sql_type==:pg #watch use of path.base_markup_dir_stub instead of stub end
create_table()
click to toggle source
# File lib/sisu/db_create.rb, line 102 def create_table def conn_exec(sql) if @sql_type==:pg conn_exec_pg(sql) elsif @sql_type==:sqlite conn_exec_sqlite(sql) end end def conn_exec_pg(sql) begin @conn.exec_params(sql) rescue if @conn.is_a?(NilClass) errmsg="No pg connection (check pg dependencies)" if @opt.act[:no_stop][:set]==:on SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, proceeding without pg output (as requested)") else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, STOPPING") exit end end end end def conn_exec_sqlite(sql) begin @conn.execute(sql) rescue if @conn.is_a?(NilClass) errmsg="No sqlite3 connection (check sqlite3 dependencies)" if @opt.act[:no_stop][:set]==:on SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, proceeding without sqlite output (as requested)") else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, STOPPING") exit end end end end def metadata_and_text if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ currently using sisu_dbi module to be populated from document files create tables metadata_and_text data import through ruby transfer } end create_metadata_and_text=%{ CREATE TABLE metadata_and_text ( tid BIGINT PRIMARY KEY, /* title */ #{column.title.create_column} #{column.title_main.create_column} #{column.title_sub.create_column} #{column.title_short.create_column} #{column.title_edition.create_column} #{column.title_note.create_column} #{column.title_language.create_column} #{column.title_language_char.create_column} /* creator */ #{column.creator_author.create_column} #{column.creator_author_honorific.create_column} #{column.creator_author_nationality.create_column} #{column.creator_editor.create_column} #{column.creator_contributor.create_column} #{column.creator_illustrator.create_column} #{column.creator_photographer.create_column} #{column.creator_translator.create_column} #{column.creator_prepared_by.create_column} #{column.creator_digitized_by.create_column} #{column.creator_audio.create_column} #{column.creator_video.create_column} /* language */ #{column.language_document.create_column} #{column.language_document_char.create_column} #{column.language_original.create_column} #{column.language_original_char.create_column} /* date */ #{column.date_added_to_site.create_column} #{column.date_available.create_column} #{column.date_created.create_column} #{column.date_issued.create_column} #{column.date_modified.create_column} #{column.date_published.create_column} #{column.date_valid.create_column} #{column.date_translated.create_column} #{column.date_original_publication.create_column} #{column.date_generated.create_column} /* publisher */ #{column.publisher.create_column} /* original */ #{column.original_publisher.create_column} #{column.original_language.create_column} #{column.original_language_char.create_column} #{column.original_source.create_column} #{column.original_institution.create_column} #{column.original_nationality.create_column} /* rights */ #{column.rights_all.create_column} #{column.rights_copyright_text.create_column} #{column.rights_copyright_translation.create_column} #{column.rights_copyright_illustrations.create_column} #{column.rights_copyright_photographs.create_column} #{column.rights_copyright_preparation.create_column} #{column.rights_copyright_digitization.create_column} #{column.rights_copyright_audio.create_column} #{column.rights_copyright_video.create_column} #{column.rights_license.create_column} /* classify */ #{column.classify_topic_register.create_column} #{column.classify_subject.create_column} #{column.classify_loc.create_column} #{column.classify_dewey.create_column} #{column.classify_keywords.create_column} /* identifier */ #{column.identifier_oclc.create_column} #{column.identifier_isbn.create_column} /* notes */ #{column.notes_abstract.create_column} #{column.notes_description.create_column} #{column.notes_comment.create_column} #{column.notes_history.create_column} #{column.notes_coverage.create_column} #{column.notes_relation.create_column} /* column.notes_source.create_column */ #{column.notes_type.create_column} #{column.notes_format.create_column} #{column.notes_prefix.create_column} #{column.notes_prefix_a.create_column} #{column.notes_prefix_b.create_column} #{column.notes_suffix.create_column} /* src */ #{column.src_filename.create_column} #{column.src_fingerprint.create_column} #{column.src_filesize.create_column} #{column.src_word_count.create_column} #{column.src_txt.create_column} /* misc */ #{column.fulltext.create_column} #{column.links.create_column.gsub(/,$/,'')} /* subj VARCHAR(64) NULL, */ /* contact VARCHAR(100) NULL, */ /* information VARCHAR(100) NULL, */ /* types CHAR(1) NULL, */ /* writing_focus_nationality VARCHAR(100) NULL, */ ); } conn_exec(create_metadata_and_text) @comment.psql.metadata_and_text if @comment end def doc_objects # create doc_objects base if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ to be populated from documents files create tables doc_objects data import through ruby transfer } end create_doc_objects=%{ CREATE TABLE doc_objects ( lid BIGINT PRIMARY KEY, metadata_tid BIGINT REFERENCES metadata_and_text, ocn SMALLINT, ocnd VARCHAR(6), ocns VARCHAR(6), clean TEXT NULL, body TEXT NULL, book_idx TEXT NULL, seg VARCHAR(256) NULL, lev_an VARCHAR(1), lev SMALLINT NULL, lev0 SMALLINT, lev1 SMALLINT, lev2 SMALLINT, lev3 SMALLINT, lev4 SMALLINT, lev5 SMALLINT, lev6 SMALLINT, lev7 SMALLINT, en_a SMALLINT NULL, en_z SMALLINT NULL, en_a_asterisk SMALLINT NULL, en_z_asterisk SMALLINT NULL, en_a_plus SMALLINT NULL, en_z_plus SMALLINT NULL, t_of VARCHAR(16), t_is VARCHAR(16), node VARCHAR(16) NULL, parent VARCHAR(16) NULL, digest_clean CHAR(#{@@dl}), digest_all CHAR(#{@@dl}), types CHAR(1) NULL ); } conn_exec(create_doc_objects) @comment.psql.doc_objects if @comment end def endnotes if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ to be populated from document files create tables endnotes data import through ruby transfer } end create_endnotes=%{ CREATE TABLE endnotes ( nid BIGINT PRIMARY KEY, document_lid BIGINT REFERENCES doc_objects, nr SMALLINT, clean TEXT NULL, body TEXT NULL, ocn SMALLINT, ocnd VARCHAR(6), ocns VARCHAR(6), digest_clean CHAR(#{@@dl}), metadata_tid BIGINT REFERENCES metadata_and_text ); } conn_exec(create_endnotes) @comment.psql.endnotes if @comment end def endnotes_asterisk if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ to be populated from document files create tables endnotes_asterisk data import through ruby transfer } end create_endnotes_asterisk=%{ CREATE TABLE endnotes_asterisk ( nid BIGINT PRIMARY KEY, document_lid BIGINT REFERENCES doc_objects, nr SMALLINT, clean TEXT NULL, body TEXT NULL, ocn SMALLINT, ocnd VARCHAR(6), ocns VARCHAR(6), digest_clean CHAR(#{@@dl}), metadata_tid BIGINT REFERENCES metadata_and_text ); } conn_exec(create_endnotes_asterisk) @comment.psql.endnotes_asterisk if @comment end def endnotes_plus if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ to be populated from document files create tables endnotes_plus data import through ruby transfer } end create_endnotes_plus=%{ CREATE TABLE endnotes_plus ( nid BIGINT PRIMARY KEY, document_lid BIGINT REFERENCES doc_objects, nr SMALLINT, clean TEXT NULL, body TEXT NULL, ocn SMALLINT, ocnd VARCHAR(6), ocns VARCHAR(6), digest_clean CHAR(#{@@dl}), metadata_tid BIGINT REFERENCES metadata_and_text ); } conn_exec(create_endnotes_plus) @comment.psql.endnotes_plus if @comment end def urls # create doc_objects file links mapping if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ currently using sisu_dbi module to be populated from doc_objects files create tables urls data import through ruby transfer } end create_urls=%{ CREATE TABLE urls ( metadata_tid BIGINT REFERENCES metadata_and_text, plaintext varchar(512), html_toc varchar(512), html_doc varchar(512), xhtml varchar(512), xml_sax varchar(512), xml_dom varchar(512), odf varchar(512), pdf_p varchar(512), pdf_l varchar(512), concordance varchar(512), latex_p varchar(512), latex_l varchar(512), digest varchar(512), manifest varchar(512), markup varchar(512), sisupod varchar(512) ); } conn_exec(create_urls) @comment.psql.urls if @comment end self end
doc_objects()
click to toggle source
# File lib/sisu/db_create.rb, line 257 def doc_objects # create doc_objects base if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ to be populated from documents files create tables doc_objects data import through ruby transfer } end create_doc_objects=%{ CREATE TABLE doc_objects ( lid BIGINT PRIMARY KEY, metadata_tid BIGINT REFERENCES metadata_and_text, ocn SMALLINT, ocnd VARCHAR(6), ocns VARCHAR(6), clean TEXT NULL, body TEXT NULL, book_idx TEXT NULL, seg VARCHAR(256) NULL, lev_an VARCHAR(1), lev SMALLINT NULL, lev0 SMALLINT, lev1 SMALLINT, lev2 SMALLINT, lev3 SMALLINT, lev4 SMALLINT, lev5 SMALLINT, lev6 SMALLINT, lev7 SMALLINT, en_a SMALLINT NULL, en_z SMALLINT NULL, en_a_asterisk SMALLINT NULL, en_z_asterisk SMALLINT NULL, en_a_plus SMALLINT NULL, en_z_plus SMALLINT NULL, t_of VARCHAR(16), t_is VARCHAR(16), node VARCHAR(16) NULL, parent VARCHAR(16) NULL, digest_clean CHAR(#{@@dl}), digest_all CHAR(#{@@dl}), types CHAR(1) NULL ); } conn_exec(create_doc_objects) @comment.psql.doc_objects if @comment end
endnotes()
click to toggle source
# File lib/sisu/db_create.rb, line 305 def endnotes if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ to be populated from document files create tables endnotes data import through ruby transfer } end create_endnotes=%{ CREATE TABLE endnotes ( nid BIGINT PRIMARY KEY, document_lid BIGINT REFERENCES doc_objects, nr SMALLINT, clean TEXT NULL, body TEXT NULL, ocn SMALLINT, ocnd VARCHAR(6), ocns VARCHAR(6), digest_clean CHAR(#{@@dl}), metadata_tid BIGINT REFERENCES metadata_and_text ); } conn_exec(create_endnotes) @comment.psql.endnotes if @comment end
endnotes_asterisk()
click to toggle source
# File lib/sisu/db_create.rb, line 331 def endnotes_asterisk if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ to be populated from document files create tables endnotes_asterisk data import through ruby transfer } end create_endnotes_asterisk=%{ CREATE TABLE endnotes_asterisk ( nid BIGINT PRIMARY KEY, document_lid BIGINT REFERENCES doc_objects, nr SMALLINT, clean TEXT NULL, body TEXT NULL, ocn SMALLINT, ocnd VARCHAR(6), ocns VARCHAR(6), digest_clean CHAR(#{@@dl}), metadata_tid BIGINT REFERENCES metadata_and_text ); } conn_exec(create_endnotes_asterisk) @comment.psql.endnotes_asterisk if @comment end
endnotes_plus()
click to toggle source
# File lib/sisu/db_create.rb, line 357 def endnotes_plus if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ to be populated from document files create tables endnotes_plus data import through ruby transfer } end create_endnotes_plus=%{ CREATE TABLE endnotes_plus ( nid BIGINT PRIMARY KEY, document_lid BIGINT REFERENCES doc_objects, nr SMALLINT, clean TEXT NULL, body TEXT NULL, ocn SMALLINT, ocnd VARCHAR(6), ocns VARCHAR(6), digest_clean CHAR(#{@@dl}), metadata_tid BIGINT REFERENCES metadata_and_text ); } conn_exec(create_endnotes_plus) @comment.psql.endnotes_plus if @comment end
metadata_and_text()
click to toggle source
# File lib/sisu/db_create.rb, line 144 def metadata_and_text if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ currently using sisu_dbi module to be populated from document files create tables metadata_and_text data import through ruby transfer } end create_metadata_and_text=%{ CREATE TABLE metadata_and_text ( tid BIGINT PRIMARY KEY, /* title */ #{column.title.create_column} #{column.title_main.create_column} #{column.title_sub.create_column} #{column.title_short.create_column} #{column.title_edition.create_column} #{column.title_note.create_column} #{column.title_language.create_column} #{column.title_language_char.create_column} /* creator */ #{column.creator_author.create_column} #{column.creator_author_honorific.create_column} #{column.creator_author_nationality.create_column} #{column.creator_editor.create_column} #{column.creator_contributor.create_column} #{column.creator_illustrator.create_column} #{column.creator_photographer.create_column} #{column.creator_translator.create_column} #{column.creator_prepared_by.create_column} #{column.creator_digitized_by.create_column} #{column.creator_audio.create_column} #{column.creator_video.create_column} /* language */ #{column.language_document.create_column} #{column.language_document_char.create_column} #{column.language_original.create_column} #{column.language_original_char.create_column} /* date */ #{column.date_added_to_site.create_column} #{column.date_available.create_column} #{column.date_created.create_column} #{column.date_issued.create_column} #{column.date_modified.create_column} #{column.date_published.create_column} #{column.date_valid.create_column} #{column.date_translated.create_column} #{column.date_original_publication.create_column} #{column.date_generated.create_column} /* publisher */ #{column.publisher.create_column} /* original */ #{column.original_publisher.create_column} #{column.original_language.create_column} #{column.original_language_char.create_column} #{column.original_source.create_column} #{column.original_institution.create_column} #{column.original_nationality.create_column} /* rights */ #{column.rights_all.create_column} #{column.rights_copyright_text.create_column} #{column.rights_copyright_translation.create_column} #{column.rights_copyright_illustrations.create_column} #{column.rights_copyright_photographs.create_column} #{column.rights_copyright_preparation.create_column} #{column.rights_copyright_digitization.create_column} #{column.rights_copyright_audio.create_column} #{column.rights_copyright_video.create_column} #{column.rights_license.create_column} /* classify */ #{column.classify_topic_register.create_column} #{column.classify_subject.create_column} #{column.classify_loc.create_column} #{column.classify_dewey.create_column} #{column.classify_keywords.create_column} /* identifier */ #{column.identifier_oclc.create_column} #{column.identifier_isbn.create_column} /* notes */ #{column.notes_abstract.create_column} #{column.notes_description.create_column} #{column.notes_comment.create_column} #{column.notes_history.create_column} #{column.notes_coverage.create_column} #{column.notes_relation.create_column} /* column.notes_source.create_column */ #{column.notes_type.create_column} #{column.notes_format.create_column} #{column.notes_prefix.create_column} #{column.notes_prefix_a.create_column} #{column.notes_prefix_b.create_column} #{column.notes_suffix.create_column} /* src */ #{column.src_filename.create_column} #{column.src_fingerprint.create_column} #{column.src_filesize.create_column} #{column.src_word_count.create_column} #{column.src_txt.create_column} /* misc */ #{column.fulltext.create_column} #{column.links.create_column.gsub(/,$/,'')} /* subj VARCHAR(64) NULL, */ /* contact VARCHAR(100) NULL, */ /* information VARCHAR(100) NULL, */ /* types CHAR(1) NULL, */ /* writing_focus_nationality VARCHAR(100) NULL, */ ); } conn_exec(create_metadata_and_text) @comment.psql.metadata_and_text if @comment end
output_dir?()
click to toggle source
# File lib/sisu/db_create.rb, line 96 def output_dir? dir=SiSU_Env::InfoEnv.new('') if @opt.act[:sqlite][:set]==:on dir.path.webserv_stub_ensure end end
urls()
click to toggle source
# File lib/sisu/db_create.rb, line 383 def urls # create doc_objects file links mapping if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ currently using sisu_dbi module to be populated from doc_objects files create tables urls data import through ruby transfer } end create_urls=%{ CREATE TABLE urls ( metadata_tid BIGINT REFERENCES metadata_and_text, plaintext varchar(512), html_toc varchar(512), html_doc varchar(512), xhtml varchar(512), xml_sax varchar(512), xml_dom varchar(512), odf varchar(512), pdf_p varchar(512), pdf_l varchar(512), concordance varchar(512), latex_p varchar(512), latex_l varchar(512), digest varchar(512), manifest varchar(512), markup varchar(512), sisupod varchar(512) ); } conn_exec(create_urls) @comment.psql.urls if @comment end