Example #1
0
    def rewrite_dataset(self):
        from ..orm import Dataset
        # Now patch up the Dataset object
        
        ds = Dataset(**self.bundle.identity.to_dict())
        ds.name = self.bundle.identity.name
        ds.vname = self.bundle.identity.vname

        self.session.merge(ds)
Example #2
0
    def create(self):
        
        """Create the database from the base SQL"""
        if not self.exists():    
            import databundles  #@UnresolvedImport
            from databundles.orm import Dataset
            from databundles.identity import Identity
            try:   
                script_str = os.path.join(os.path.dirname(databundles.__file__),
                                          Database.PROTO_SQL_FILE)
            except:
                # Not sure where to find pkg_resources, so this will probably
                # fail. 
                from pkg_resources import resource_string #@UnresolvedImport
                script_str = resource_string(databundles.__name__, Database.PROTO_SQL_FILE)
         
            dir_ = os.path.dirname(self.path);
            
            if not os.path.isdir(dir_):
                os.makedirs(dir_)
         
            self.load_sql(script_str)
            
            # Create the Dataset
            s =  self.session
            ds = Dataset(**self.bundle.config.identity)
            ds.name = Identity.name_str(ds)
           
            s.add(ds)
            s.commit()
 
            
            # call the post create function
            if self._post_create:
                self._post_create(self)
            
        return self
Example #3
0
    def _create(self):
        """Create the database from the base SQL"""
        from databundles.orm import  Dataset, Partition, Table, Column, File
        from ..identity import new_identity
        from sqlalchemy.orm import sessionmaker


        tables = [ Dataset, Partition, Table, Column, File ]

        for table in tables:
            table.__table__.create(bind=self.engine)

        # Create the Dataset record
        session = self.creation_session
        
        ds = Dataset(**self.bundle.config.identity)

        ident = new_identity(self.bundle.config.identity)
        
        ds.name = ident.name
        ds.vname = ident.vname

        session.add(ds)
        session.commit()