gboolean
ephy_history_service_initialize_urls_table (EphyHistoryService *self)
{
  GError *error = NULL;

  if (ephy_sqlite_connection_table_exists (self->history_database, "visits")) {
    return TRUE;
  }
  ephy_sqlite_connection_execute (self->history_database,
                                  "CREATE TABLE urls ("
                                  "id INTEGER PRIMARY KEY,"
                                  "host INTEGER NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,"
                                  "url LONGVARCAR,"
                                  "title LONGVARCAR,"
                                  "sync_id LONGVARCAR,"
                                  "visit_count INTEGER DEFAULT 0 NOT NULL,"
                                  "typed_count INTEGER DEFAULT 0 NOT NULL,"
                                  "last_visit_time INTEGER,"
                                  "thumbnail_update_time INTEGER DEFAULT 0," /* this column is legacy, unused */
                                  "hidden_from_overview INTEGER DEFAULT 0)", &error);

  if (error) {
    g_warning ("Could not create urls table: %s", error->message);
    g_error_free (error);
    return FALSE;
  }
  return TRUE;
}
gboolean
ephy_history_service_initialize_hosts_table (EphyHistoryService *self)
{
  EphyHistoryServicePrivate *priv = EPHY_HISTORY_SERVICE (self)->priv;
  GError *error = NULL;

  if (ephy_sqlite_connection_table_exists (priv->history_database, "hosts")) {
    return TRUE;
  }
  ephy_sqlite_connection_execute (priv->history_database,
    "CREATE TABLE hosts ("
    "id INTEGER PRIMARY KEY,"
    "url LONGVARCAR,"
    "title LONGVARCAR,"
    "visit_count INTEGER DEFAULT 0 NOT NULL,"
    "zoom_level REAL DEFAULT 1.0)", &error);

  if (error) {
    g_error("Could not create hosts table: %s", error->message);
    g_error_free (error);
    return FALSE;
  }
  ephy_history_service_schedule_commit (self);
  return TRUE;
}
gboolean
ephy_history_service_initialize_hosts_table (EphyHistoryService *self)
{
  GError *error = NULL;

  if (ephy_sqlite_connection_table_exists (self->history_database, "hosts")) {
    return TRUE;
  }
  ephy_sqlite_connection_execute (self->history_database,
                                  "CREATE TABLE hosts ("
                                  "id INTEGER PRIMARY KEY,"
                                  "url LONGVARCAR,"
                                  "title LONGVARCAR,"
                                  "visit_count INTEGER DEFAULT 0 NOT NULL,"
                                  "zoom_level REAL DEFAULT 0.0)", &error);

  if (error) {
    g_warning ("Could not create hosts table: %s", error->message);
    g_error_free (error);
    return FALSE;
  }
  return TRUE;
}
gboolean
ephy_history_service_initialize_visits_table (EphyHistoryService *self)
{
  GError *error = NULL;

  if (ephy_sqlite_connection_table_exists (self->history_database, "visits"))
    return TRUE;

  ephy_sqlite_connection_execute (self->history_database,
                                  "CREATE TABLE visits ("
                                  "id INTEGER PRIMARY KEY,"
                                  "url INTEGER NOT NULL REFERENCES urls(id) ON DELETE CASCADE,"
                                  "visit_time INTEGER NOT NULL,"
                                  "visit_type INTEGER NOT NULL,"
                                  "referring_visit INTEGER)", &error);

  if (error) {
    g_warning ("Could not create visits table: %s", error->message);
    g_error_free (error);
    return FALSE;
  }

  return TRUE;
}