Switching to the new wview_extended schema - weewx/weewx GitHub Wiki
WeeWX V4.x offers a new schema wview_extended
, with many new types. You may
find many of these types useful and want to switch to it. Before explaining how
to do this, it's worth noting:
-
In WeeWX, the schemas found in
schemas/wview.py
andschemas/wview_extended.py
are used only when the database is created. Thereafter, the schema is read from the database itself, and the Python versions are not used again. -
While
wview_extended
is the new, default, schema for V4.x, it is not necessary to "upgrade" to it. Your oldwview
schema will continue to work just fine. Switch to the new schema only if you find the new types useful. -
If you just need to add one or two new types, you may find it easier to use the tool
weectl database add-column
.
Here's how to switch. Note that these instructions are just a variant on the instructions in section _Reconfigure database using a new schema of the Customizing Guide.
These instructions assume that you are using WeeWX V5.x
-
We will be using the utility
weectl database
to do the switch. -
Stop
weewxd
. -
Modify
wx_binding
. When it creates the new, modified database,weectl database
needs to know to use thewview_extended
schema instead of the old,wview
schema. You do this by changing the optionschema
in section[DataBindings]
inweewx.conf
.The
[DataBindings]
section now looks like this:[DataBindings] [[wx_binding]] # The database option is unchanged. If you are using MySQL, it should be archive_mysql database = archive_sqlite table_name = archive # Older installs will use weewx.wxmanager.WXDaySummaryManager instead of weewx.manager.DaySummaryManager. Doesn't matter. manager = weewx.manager.DaySummaryManager # Specify the new, extended schema here: schema = schemas.wview_extended.schema
Note that for the
manager
option, you can use eitherweewx.manager.DaySummaryManager
orweewx.wxmanager.WXDaySummaryManager
. -
Check permissions.
weectl database
will create a new database with the same name as the old, except with the suffix_new
attached to the end. Make sure you have the necessary permissions to create it. In particular, if you are using MySQL, you will needCREATE
privileges:mysql> GRANT select, update, create, delete, insert ON weewx_new.* TO weewx@localhost;
-
Create and populate the new database. Now run the utility
weectl database
with thereconfigure
action. If your configuration fileweewx.conf
is in an unusual position, you may have to specify its path using the--config
option.weectl database reconfigure
This will create a new database (nominally,
weewx.sdb_new
if you are using SQLite,weewx_new
if you are using MySQL) using the new schema and populate it with data from the old database. -
Shuffle the databases.
Warning! Make a backup of the data before doing any of the next steps!
For this step, we will shuffle the databases around so the new database has the name of the old database.
For SQLite:
cd <sqlite directory> mv weewx.sdb_new weewx.sdb
where
<sqlite directory>
represents the location of your database. If you did a package (e.g., Debian) install, this would generally be/var/lib/weewx
. If you did asetup.py
install, it's/home/weewx/archive
.For MySQL:
mysql -u <username> --password=<mypassword> mysql> DROP DATABASE weewx; # Delete the old database mysql> CREATE DATABASE weewx; # Create a new one with the same name mysql> RENAME TABLE weewx_new.archive TO weewx.archive; # Rename to the nominal name
-
Build the daily summaries. Finally, the daily summaries inside the database have to be built. This will be done automatically by
weewxd
when it starts up, but it's good practice to do this manually, as this process can take some time:weectl database rebuild-daily
-
Restart
weewxd
.