artaylor

Converting legacy data to PW with foreign keys

Recommended Posts

Hi,

I have a project that, based on initial specs, I decided to build in another framework due to the client wanting the ability to regularly import data from an existing manufacturing system. I decided a platform that would allow me to match the imported data to the system would make sense. Since then, the project has morphed (I know, it never happens) and the regular import is unnecessary and so a comprehensive admin is needed. I want to switch to PW but don't want to have to manually link thousands of tables.

I have the import routine working for the main table but I am not sure how to import the support tables and automatically create the page fields for them.

Oh, in case it matter, the links are not autoincrement id fields, but character codes. Eg. Category table - code: TRN, description: Transportation

If someone can point me in the right direction it would be much appreciated.

Share this post


Link to post
Share on other sites

Literally thousands of tables or just thousands of rows/records?

  • Like 1

Share this post


Link to post
Share on other sites

Ah, that reads a lot more doable then :)

For a dozen tables, I'd probably create the templates and their fields by hand as it is a one-time thing. Perhaps you can name the templates like the old tables for easier coding later. Then create a page field on the main template for every linked table and limit it to the according support table template. Your import routine can focus on creating pages with the correct template and filling in the data. The old id can just go into a dedicated field in the support template, and once all your support table pages have been created, you can use simple selectors like $pages->get("template=oldtablename, keyfield=TRN") to get the correct page to link to when you import the main page/table. Depending on whether you need to display the link codes, you can hide or even drop the field in the support templates.

I'm assuming most support tables will be relatively simple and a template with a title and one extra field for the db id code should be sufficient.

  • Like 3

Share this post


Link to post
Share on other sites

@BitPoet Thanks for the info.

While I have built a few PW sites, I have not had to go much beyond installing some modules and doing basic PW things. I have not gotten to the level of using the API to add data, etc, so if you don't mind sharing a quick snippet of the "import" routine, I would appreciate it. I don't want to take too much of your time, so please ignore this request if it is a lot of time and energy.

Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By rareyush
      i am receiving and error whenever I try to run my processwire on localhost,

       
       
      sql code
       
      -- -- Table structure for table `field_fieldset_meta_end` -- CREATE TABLE `field_fieldset_meta_end` ( `pages_id` int(10) UNSIGNED NOT NULL, `data` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- -- -- Table structure for table `field_fieldset_meta_END` -- CREATE TABLE `field_fieldset_meta_END` ( `pages_id` int(10) UNSIGNED NOT NULL, `data` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; anyone ?
      whenever I make a new database and upload it there, database get imported without errors.
    • By modifiedcontent
      I have one central website, with membership registration and content etc., and then several related websites with their own URL/domains, each on Processwire, all on the same server.
      I would like to access the database of the central website from the sister websites. How would I do that?
      You can't bootstrap one PW installation into another. You can include template parts from one in the other by just using the server path, but whatever you try to get/post just comes/goes to the database of the site you are on.
      Could you switch databases by including the config.php from another PW installation somewhere?
      What is the correct, secure way to do this?
    • By answersmode
      Please help me........
      DATABASE CONNECTION PROBLEM  - CREATE DATABASE IF NOT EXISTS `lwteswm664_ltingesjfo_itbd` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
      Error
      SQL query:
       
      -- -- Database: `lwteswm664_ltingesjfo_itbd` -- CREATE DATABASE IF NOT EXISTS `lwteswm664_ltingesjfo_itbd` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;  
      MySQL said:
      #1044 - Access denied for user 'newhost'@'localhost' to database 'lwteswm664_ltingesjfo_itbd' 
       
      I'm facing this peoblem in my website xxxxx and xxxxx When I wanted to upload my databaz backup file.
      Now what can I do?
      Please help me........
       
       

    • By thmsnhl
      Hi everybody,
      we started our first Processwire driven project in my new company and for the first time, I was working on one site with more than 2 colleagues on the same site.
      It didn't take long for us to stumble across some problems when multiple developers work at the same time, conflicts with updating the database on vagrant machines, like duplicate entries for page IDs, errors when setting up fields and stuff like this. We ended up working on a dedicated database server, that we linked to our vagrant machines and most of the problems were gone, but the performance of this constellation is really bad compared to our first approach with database running on vagrant machines.
      I already tried to find a solution in the forums but I couldn't find anyone with problems like this.
      So I was wondering: how do you manage projects with multiple developers on vagrant machines in a git-based workflow?
    • By hezmann
      Hi!  I've just started on ProcessWire, coming from Wordpress.  I've done several sites in WP but this new one is just to data driven for Wordpress to handle without so many plugins and custom code it just seemed like there must be a better option so here I am.  I used to do a lot of stuff in Access (many years ago) and have some experience with PHP/MySQL.
      I've had a look at a few tutorials and created the planets website etc.  I have a specific structure that I'm looking to create so thought I would ask for some expert advice before making every mistake in the book.
      I do a lot of long distance (inn to inn) walking and am always looking for new ones which involves searching many different sites.  I've yet to find a good repository for this type of thing so thought I would build my own.  The basic structure is (more info added later but trying to get basic idea of best practices):
       
      Walks -> Walk Variations <->Walk Segments <-> Walk Towns (go into Walk Segments as Start and End Towns).
      Walks <->Links
      Walk Towns <-> Accomodation, Walk Towns <-> Dining
      Should I be using ProFields?  How should I structure this as far as fields/templates?
      Thanks in advance for your help.
      Heather